1 /* 2 Relay -- a tool to record and play Quake2 demos 3 Copyright (C) 2000 Conor Davis 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License 7 as published by the Free Software Foundation; either version 2 8 of the License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 Conor Davis 20 cedavis@planetquake.com 21 */ 22 23 #ifndef __SV_LOCAL_H 24 #define __SV_LOCAL_H 25 26 #include <stdio.h> 27 #include <stdlib.h> 28 #include <string.h> 29 30 #include "shared.h" 31 #include "q2defines.h" 32 33 #include "block.h" 34 35 #include "cmd.h" 36 37 #include "dm2.h" 38 39 #include "endian.h" 40 41 #include "mem.h" 42 43 #include "menu.h" 44 45 #include "net.h" 46 47 #include "pak.h" 48 49 #include "q2utils.h" 50 51 #include "utils.h" 52 53 54 55 #define FRAMETIME 0.1 56 57 58 59 // timeout settings (in milliseconds) 60 61 #define CHALLENGE_TIMEOUT 3000 62 63 #define CLIENT_TIMEOUT 30000 64 65 66 67 // menu stuff 68 69 70 71 enum 72 73 { 74 75 MENU_BAD, 76 77 MENU_MAIN, 78 79 MENU_DEMO, 80 81 MENU_PLAYERS, 82 83 MENU_SETTINGS, 84 85 }; 86 87 88 89 #if 0 90 91 enum 92 93 { 94 95 MENU_ALIGN_LEFT, 96 97 MENU_ALIGN_CENTER, 98 99 MENU_ALIGN_RIGHT 100 101 }; 102 103 104 105 #define MAX_MENU_PARMS 8 106 107 108 109 typedef struct client_s client_t; 110 111 112 113 typedef struct menuitem_s 114 115 { 116 117 char *text; // text to be displayed 118 119 int align; // left, center, right 120 121 int indent; // pixels to indent to the right 122 123 int param[MAX_MENU_PARMS]; // params used by the Select function 124 125 void (*Select)(client_t *client, struct menuitem_s *item, int key); 126 127 } menuitem_t; 128 129 130 131 typedef struct menu_s 132 133 { 134 135 char *title; // always displayed at top 136 137 int id; // ID_* menu type 138 139 menuitem_t *items; // item array 140 141 int num; // number of items 142 143 int top; // index of first item to be displayed 144 145 int cur; // current selected item 146 147 int param[MAX_MENU_PARMS]; // params used by the Show function 148 149 void (*Show)(client_t *client, struct menu_s *menu); 150 151 void (*Close)(client_t *client, struct menu_s *menu); 152 153 struct menu_s *next; 154 155 } menu_t; 156 157 #endif 158 159 160 161 typedef struct 162 163 { 164 165 player_state_t ps; 166 167 byte active[MAX_EDICTS/8]; 168 169 } clientdelta_t; 170 171 172 173 typedef struct client_s 174 175 { 176 177 enum 178 179 { 180 181 CL_UNCONNECTED, // not connected 182 183 CL_CONNECTING, // successfully challenged, waiting for 184 185 // "new" command 186 187 CL_CONFIGSTRINGS, // receiving serverdata/configstrings 188 189 CL_BASELINES, // receiving baselines 190 191 CL_PRECACHING, // precaching 192 193 CL_CONNECTED // ready to receive frame updates 194 195 } status; 196 197 net_t net; 198 199 size_t timeout_time; 200 201 int protocol; 202 203 size_t delta_frame; 204 205 char userinfo[MAX_INFO_STRING]; 206 207 char netname[16]; 208 209 210 211 // message packets 212 213 block_t unreliable; 214 215 char unreliable_buffer[MAX_MSGLEN]; 216 217 block_t reliable; 218 219 char reliable_buffer[MAX_MSGLEN]; 220 221 block_t nextreliable; 222 223 char nextreliable_buffer[MAX_MSGLEN]; 224 225 226 227 clientdelta_t old[UPDATE_BACKUP]; 228 229 player_state_t ps; 230 231 byte active[MAX_EDICTS/8]; 232 233 char layout[MAX_MSGLEN]; 234 235 short inventory[MAX_ITEMS]; 236 237 qboolean layout_modified; 238 239 qboolean inventory_modified; 240 241 242 243 int player; 244 245 int flags; 246 247 float dist; 248 249 vec3_t origin; 250 251 vec3_t velocity; 252 253 vec3_t cmd_angles; 254 255 int buttons; 256 257 menu_t *curmenu; 258 259 } client_t; 260 261 262 263 typedef struct 264 265 { 266 267 enum {SV_IDLE, SV_RUNNING} status; 268 269 char *console_commandstring; 270 271 char *demo_commandstring; 272 273 PFILE *infile; 274 275 SOCKET socket; 276 277 size_t nextcommand_time; 278 279 int maxclients; 280 281 int numclients; 282 283 serverdata_t outsvd; 284 285 byte current_connected[MAX_CLIENTS/8]; 286 287 288 289 cvar_t *cvars; 290 291 client_t *clients; 292 293 } server_t; 294 295 296 297 // 298 299 // FUNCTIONS 300 301 // 302 303 304 305 // sv_challenge.c 306 307 extern int NewChallenge(struct sockaddr_in *addr); 308 309 extern qboolean FindChallenge(struct sockaddr_in *addr, int id); 310 311 extern void TimeoutChallenges(); 312 313 extern void FreeAllChallenges(); 314 315 316 317 // sv_clcmds.c 318 319 extern void ClientCommand(client_t *client); 320 321 extern void CL_StringCommand(client_t *client); 322 323 extern void ConnectionlessCommand(struct sockaddr_in *addr); 324 325 326 327 // sv_client.c 328 329 extern void InitClient(client_t *client); 330 331 extern int CL_ChangePlayer(client_t *client, int index); 332 333 extern void ClientDisconnect(client_t *client); 334 335 extern void ClientTimeout(client_t *client); 336 337 extern qboolean ClientConnect(client_t *client, const char *userinfo); 338 339 extern void ClientBegin(client_t *client); 340 341 extern void ClientUserinfoChanged(client_t *client, const char *userinfo); 342 343 extern void ClientThink(client_t *client, const usercmd_t *cmd); 344 345 extern void ClientBeginServerFrame(client_t *client); 346 347 extern void UpdateClientOrigin(client_t *client); 348 349 extern void ClientEndServerFrame(client_t *client); 350 351 352 353 // sv_cvar.c 354 355 extern cvar_t *cvar(const char *var_name, const char *value, int flags); 356 357 extern void cvar_set(const char *var_name, const char *value); 358 359 extern void cvar_forceset(const char *var_name, const char *value); 360 361 extern void UnlatchCvars(); 362 363 extern void FreeAllCvars(); 364 365 366 367 // sv_dm2.c 368 369 extern int PreFrame_Read(); 370 371 extern int Frame_Read(); 372 373 extern void CL_WriteEntities(block_t *block, client_t *client, size_t delta_frame); 374 375 376 377 // sv_main.c 378 379 extern server_t server; 380 381 extern dm2_t dm2in; 382 383 extern bsp_t map; 384 385 extern cvar_t *cvar_basedir; 386 387 extern cvar_t *cvar_demoname; 388 389 extern cvar_t *cvar_game; 390 391 extern cvar_t *cvar_hostname; 392 393 extern cvar_t *cvar_mapname; 394 395 extern cvar_t *cvar_maxclients; 396 397 extern cvar_t *cvar_password; 398 399 extern cvar_t *cvar_port; 400 401 extern cvar_t *cvar_protocol; 402 403 extern cvar_t *cvar_timescale; 404 405 extern void SpawnServer(const char *filename); 406 407 extern void KillServer(const char *message); 408 409 extern void CloseProgram(int err); 410 411 extern void Error(const char *fmt, ...); 412 413 extern void DropClient(client_t *client, const char *fmt, ...); 414 415 extern void CL_cprintf(block_t *block, int printlevel, const char *fmt, ...); 416 417 extern void CL_bprintf(qboolean reliable, int printlevel, const char *fmt, ...); 418 419 420 421 #if 0 422 423 // sv_menu.c 424 425 extern void Menu_Close(client_t *client, qboolean update); 426 427 extern void Menu_CloseAll(client_t *client, qboolean update); 428 429 extern int Menu_AddItem(const char *text, const char *fmt, ...); 430 431 extern void Menu_Display(client_t *client); 432 433 extern void Menu_Update(client_t *client, int id); 434 435 extern void Menu_UpdateAll(int id); 436 437 extern void Menu_Prev(client_t *client); 438 439 extern void Menu_Next(client_t *client); 440 441 extern void Menu_Select(client_t *client, int key); 442 443 extern void Menu_SelectOpen(client_t *client, menuitem_t *item, int key); 444 445 extern void Menu_Start(menu_t *menu); 446 447 extern void Menu_Finish(menu_t *menu); 448 449 extern void Menu_Open(client_t *client, void (*Show)(client_t *, struct menu_s *), const char *fmt, ...); 450 451 #endif 452 453 454 455 // sv_menus.c 456 457 extern void UpdateLayout(client_t *client); 458 459 extern void OpenMenu(client_t *client, void (*Show)(menu_t *)); 460 461 extern void CloseMenu(client_t *client); 462 463 extern void CloseAllMenus(client_t *client); 464 465 extern void MainMenu_Show(menu_t *menu); 466 467 468 469 // sv_net.c 470 471 extern void ReadPackets(); 472 473 extern void WritePackets(); 474 475 476 477 // sv_pmove.c 478 479 extern void Pmove(pmove_t *pm); 480 481 482 483 // sv_svcmds.c 484 485 extern void FreeAllAliases(); 486 487 extern qboolean RunConsoleCommand(); 488 489 490 491 #endif // __SV_LOCAL_H 492 493