3 * Daniel Nelson - 8/29/0
5 * Copyright (C) 2000 Daniel Nelson
6 * Copyright (C) 2004 Andrew Sayman
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Daniel Nelson - aluminumangel.org
40 #include "TextureLoader.h"
43 #include "Communicator.h"
44 #include "MetaState.h"
48 #include "gtk-gui/gui_main.h"
51 #define GC_HOST_NAME_SIZE (256)
55 * html tables don't work right in explorer
59 * slow if left sitting a long time before game start
61 * central server for online game setup
62 * remove dying_count_2
63 * find and use correct GL_LIGHT_MODEL_COLOR_CONTROL defines
66 int main ( int argc
, char **argv
)
69 return gui_main(argc
, argv
);
71 char player_name
[GC_PLAYER_NAME_LENGTH
];
72 char host_name
[GC_HOST_NAME_SIZE
];
76 parseCommandLine(argc
, argv
, mode
, port
, host_name
, player_name
);
77 run_crack_attack(mode
, port
, host_name
, player_name
, -1, -1);
85 cerr
<< "Usage: " GC_BINARY
" --server [PORT] [--low] [-X] [--wait] "
88 " " GC_BINARY
" SERVER[:PORT] [--low] [--name 'NAME']\n"
90 " " GC_BINARY
" --solo [--low] [-X] [--name 'NAME']"
95 void run_crack_attack (
103 cerr
<< "Player name not properly allocated" << endl
;
107 if (player_name
[0] == '\0') {
109 struct passwd
*uinfo
= getpwuid(getuid());
111 strncpy(player_name
, uinfo
->pw_name
, GC_PLAYER_NAME_LENGTH
);
112 for (int n
= strlen(player_name
); n
--; )
113 player_name
[n
] = toupper(player_name
[n
]);
115 strncpy(player_name
, GC_DEFAULT_PLAYER_NAME
, GC_PLAYER_NAME_LENGTH
);
117 strncpy(player_name
, GC_DEFAULT_PLAYER_NAME
, GC_PLAYER_NAME_LENGTH
);
121 cout
<< GC_MESSAGE
<< endl
;
123 setupLocalDataDirectory();
125 if (!(mode
& CM_SOLO
))
126 Communicator::initialize(mode
, port
, host_name
, player_name
);
128 Random::seed(Random::generateSeed());
130 MetaState::programStart(mode
, player_name
, width
, height
);
135 void parseCommandLine ( int argc
, char **argv
, int &mode
, int &port
,
136 char *host_name
, char *player_name
)
138 for (int n
= 1; argv
[n
]; n
++) {
140 if (!strcmp(argv
[n
], "-s") || !strcmp(argv
[n
], "--server")) {
141 if (mode
& (CM_SERVER
| CM_CLIENT
| CM_SOLO
)) usage();
144 if (argv
[n
+ 1] && argv
[n
+ 1][0] != '-')
145 port
= atoi(argv
[++n
]);
149 } else if (!strcmp(argv
[n
], "-1") || !strcmp(argv
[n
], "--solo")) {
150 if (mode
& (CM_SERVER
| CM_CLIENT
| CM_SOLO
)) usage();
154 } else if (!strcmp(argv
[n
], "-n") || !strcmp(argv
[n
], "--name")) {
155 if (!argv
[n
+ 1]) usage();
157 strncpy(player_name
, argv
[++n
], GC_PLAYER_NAME_LENGTH
);
158 player_name
[GC_PLAYER_NAME_LENGTH
- 1] = '\0';
159 for (char *p
= player_name
; *p
; p
++)
160 if (!isprint(*p
)) *p
= ' ';
162 } else if (!strcmp(argv
[n
], "-l") || !strcmp(argv
[n
], "--low"))
164 mode
|= CM_LOW_GRAPHICS
;
166 else if (!strcmp(argv
[n
], "-X") || !strcmp(argv
[n
], "--extreme"))
170 else if (!strcmp(argv
[n
], "-w") || !strcmp(argv
[n
], "--wait"))
171 mode
|= CM_NO_TIME_OUT
;
174 if (mode
& (CM_SERVER
| CM_CLIENT
| CM_SOLO
)) usage();
177 strncpy(host_name
, argv
[n
], GC_HOST_NAME_SIZE
);
178 char *ptr
= strchr(host_name
, ':');
180 port
= atoi(ptr
+ 1);
187 if (!(mode
& (CM_SERVER
| CM_CLIENT
| CM_SOLO
)))
190 if ((mode
& CM_NO_TIME_OUT
) && !(mode
& CM_SERVER
))
194 void setupLocalDataDirectory ( )
196 char local_directory
[256];
197 TextureLoader::buildLocalDataDirectoryName(local_directory
);
198 if (!TextureLoader::fileExists(local_directory
)
200 && mkdir(local_directory
, 0777)) {
202 && _mkdir(local_directory
)) {
204 cerr
<< "Error creating local data directory '" << local_directory