1 /*
2 * XPilotNG/SDL, an SDL/OpenGL XPilot client.
3 *
4 * Copyright (C) 2003-2004 Juha Lindstr�m <juhal@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "xpclient_sdl.h"
22
23 #include "sdlinit.h"
24 #include "sdlmeta.h"
25
Main_shutdown(void)26 static void Main_shutdown(void)
27 {
28 Net_cleanup();
29 Client_cleanup();
30 }
31
sigcatch(int signum)32 static void sigcatch(int signum)
33 {
34 signal(SIGINT, SIG_IGN);
35 signal(SIGTERM, SIG_IGN);
36 Main_shutdown();
37 error("got signal %d\n", signum);
38 exit(1);
39
40 }
41
Program_name(void)42 const char *Program_name(void)
43 {
44 return "xpilot-ng-sdl";
45 }
46
main(int argc,char * argv[])47 int main(int argc, char *argv[])
48 {
49 bool auto_shutdown = false;
50 int result;
51
52 init_error(argv[0]);
53
54 seedMT((unsigned)time(NULL) ^ Get_process_id());
55
56 memset(&connectParam, 0, sizeof(Connect_param_t));
57 connectParam.contact_port = SERVER_PORT;
58 connectParam.team = TEAM_NOT_SET;
59
60 Store_default_options();
61 Store_talk_macro_options();
62 Store_key_options();
63 Store_sdlinit_options();
64 Store_sdlgui_options();
65 Store_radar_options();
66
67 memset(&xpArgs, 0, sizeof(xp_args_t));
68 Parse_options(&argc, argv);
69
70 /* CLIENTRANK */
71 Init_saved_scores();
72
73 if (sock_startup()) {
74 error("failed to initialize networking");
75 exit(1);
76 }
77
78 if (xpArgs.text || xpArgs.auto_connect || argv[1]) {
79 if (!Contact_servers(argc - 1, &argv[1],
80 xpArgs.auto_connect, xpArgs.list_servers,
81 auto_shutdown, xpArgs.shutdown_reason,
82 0, NULL, NULL, NULL, NULL,
83 &connectParam))
84 return 0;
85 if (Init_window()) {
86 error("Could not initialize SDL, check your settings.");
87 exit(1);
88 }
89 } else {
90 if (Init_window()) {
91 error("Could not initialize SDL, check your settings.");
92 exit(1);
93 }
94 while (1) {
95 result = Meta_window(&connectParam);
96 if (result < 0) return 0;
97 if (result == 0) break;
98 }
99 }
100
101 /* If something goes wrong before Client_setup I'll leave the
102 * cleanup to the OS because afaik Client_cleanup will clean
103 * stuff initialized in Client_setup. */
104
105 if (Client_init(connectParam.server_name, connectParam.server_version)) {
106 error("failed to initialize client");
107 exit(1);
108 }
109
110
111 if (Net_init(connectParam.server_addr, connectParam.login_port)) {
112 error("failed to initialize networking");
113 exit(1);
114 }
115 if (Net_verify(connectParam.user_name,
116 connectParam.nick_name,
117 connectParam.disp_name)) {
118 error("failed to verify networking");
119 exit(1);
120 }
121 if (Net_setup()) {
122 error("failed to setup networking");
123 exit(1);
124 }
125 if (Client_setup()) {
126 error("failed to setup client");
127 exit(1);
128 }
129
130 signal(SIGINT, sigcatch);
131 signal(SIGTERM, sigcatch);
132
133 if (Net_start()) {
134 Main_shutdown();
135 error("failed to start networking");
136 exit(1);
137 }
138 if (Client_start()) {
139 Main_shutdown();
140 error("failed to start client");
141 exit(1);
142 }
143 Game_loop();
144 Main_shutdown();
145 return 0;
146 }
147