client_t *ClientReliableWrite_BeginSplit(client_t *cl, int svc, int svclen) { if (cl->controller) { //this is a slave client. //find the right number and send. client_t *sp; int pnum = 0; for (sp = cl->controller; sp; sp = sp->controlled) { if (sp == cl) break; pnum++; } sp = cl->controller; ClientReliableWrite_Begin (sp, svcfte_choosesplitclient, 2+svclen); ClientReliableWrite_Byte (sp, pnum); ClientReliableWrite_Byte (sp, svc); return sp; } else { ClientReliableWrite_Begin (cl, svc, svclen); return cl; } }
void SV_NextDownload_f (void) { byte buffer[1024]; int r; int percent; int size; if (!host_client->download) return; r = host_client->downloadsize - host_client->downloadcount; if (r > 768) r = 768; r = fread (buffer, 1, r, host_client->download); ClientReliableWrite_Begin (host_client, svc_download, 6+r); ClientReliableWrite_Short (host_client, r); host_client->downloadcount += r; size = host_client->downloadsize; if (!size) size = 1; percent = host_client->downloadcount*100/size; ClientReliableWrite_Byte (host_client, percent); ClientReliableWrite_SZ (host_client, buffer, r); if (host_client->downloadcount != host_client->downloadsize) return; fclose (host_client->download); host_client->download = NULL; }
void SV_Pings_f (void) { client_t *client; int j; for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++) { if (client->state != cs_spawned) continue; ClientReliableWrite_Begin (host_client, svc_updateping, 4); ClientReliableWrite_Byte (host_client, j); ClientReliableWrite_Short (host_client, SV_CalcPing(client)); ClientReliableWrite_Begin (host_client, svc_updatepl, 4); ClientReliableWrite_Byte (host_client, j); ClientReliableWrite_Byte (host_client, client->lossage); } }
void SV_EndChat(void) { host_client->chat.active = false; host_client->chat.time=0; ClientReliableWrite_Begin (host_client, svc_centerprint, 2); ClientReliableWrite_String (host_client, ""); /* MSG_WriteByte(&sv.reliable_datagram, svc_chat); MSG_WriteString(&sv.reliable_datagram, ""); */ }
void SV_Snap (int uid) { client_t *cl; char pcxname[80]; char checkname[MAX_OSPATH]; int i; for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { if (!cl->state) continue; if (cl->userid == uid) break; } if (i >= MAX_CLIENTS) { Con_Printf ("userid not found\n"); return; } sprintf(pcxname, "%d-00.pcx", uid); sprintf(checkname, "%s/snap", gamedirfile); Sys_mkdir(gamedirfile); Sys_mkdir(checkname); for (i=0 ; i<=99 ; i++) { pcxname[strlen(pcxname) - 6] = i/10 + '0'; pcxname[strlen(pcxname) - 5] = i%10 + '0'; sprintf (checkname, "%s/snap/%s", gamedirfile, pcxname); if (Sys_FileTime(checkname) == -1) break; // file doesn't exist } if (i==100) { Con_Printf ("Snap: Couldn't create a file, clean some out.\n"); return; } strcpy(cl->uploadfn, checkname); memcpy(&cl->snap_from, &net_from, sizeof(net_from)); if (sv_redirected != RD_NONE) cl->remote_snap = true; else cl->remote_snap = false; ClientReliableWrite_Begin (cl, svc_stufftext, 24); ClientReliableWrite_String (cl, "cmd snap"); Con_Printf ("Requesting snap from user %d...\n", uid); }
void SV_SendChat(void) { int l; int i; char *s, *s2, *text; l = 2 + strlen(host_client->chat.maintext)+2; for (i = 0; i < host_client->chat.options; i++) l += strlen(host_client->chat.option[i].text)+2; s = Z_Malloc(l+1); s2 = s; text = host_client->chat.maintext; while(*text) { *s2 = *text ^ 128; text++; s2++; } *s2++='\n'; *s2++='\n'; *s2='\0'; for (i = 0; i < host_client->chat.options; i++) { strcat(s2, host_client->chat.option[i].text); strcat(s2, "\n\n"); } ClientReliableWrite_Begin (host_client, svc_centerprint, 2 + l); ClientReliableWrite_String (host_client, s); /* MSG_WriteByte(&sv.reliable_datagram, svc_chat); if (!*host_client->chat.maintext) //no text. don't mix with ends MSG_WriteString(&sv.reliable_datagram, " "); else MSG_WriteString(&sv.reliable_datagram, host_client->chat.maintext); MSG_WriteByte(&sv.reliable_datagram, i); for (i = 0; i < host_client->chat.options; i++) MSG_WriteString(&sv.reliable_datagram, host_client->chat.option[i].text); */ host_client->chat.time = sv.time+SENDDELAY; }
void SV_TogglePause (const char *msg) { int i; client_t *cl; sv.paused ^= 1; if (msg) SV_BroadcastPrintf (PRINT_HIGH, "%s", msg); // send notification to all clients for (i=0, cl = svs.clients ; i<MAX_CLIENTS ; i++, cl++) { if (!cl->state) continue; ClientReliableWrite_Begin (cl, svc_setpause, 2); ClientReliableWrite_Byte (cl, sv.paused); } }
void SV_Snap (int uid) { client_t *cl; char pcxname[80], checkname[MAX_OSPATH]; int i; FILE *f; for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { if (cl->state < cs_connected) continue; if (cl->userid == uid) break; } if (i >= MAX_CLIENTS) { Com_Printf ("userid not found\n"); return; } FS_CreatePath (va("%s/snap/", com_gamedir)); snprintf (pcxname, sizeof (pcxname), "%d-00.pcx", uid); for (i = 0; i <= 99; i++) { pcxname[strlen(pcxname) - 6] = i / 10 + '0'; pcxname[strlen(pcxname) - 5] = i % 10 + '0'; snprintf (checkname, sizeof(checkname), "%s/snap/%s", com_gamedir, pcxname); if (!(f = fopen (checkname, "rb"))) break; // file doesn't exist fclose (f); } if (i == 100) { Com_Printf ("Snap: Couldn't create a file, clean some out.\n"); return; } strlcpy (cl->uploadfn, checkname, sizeof (cl->uploadfn)); memcpy(&cl->snap_from, &net_from, sizeof(net_from)); cl->remote_snap = (sv_redirected != RD_NONE); ClientReliableWrite_Begin (cl, svc_stufftext, 24); ClientReliableWrite_String (cl, "cmd snap\n"); Com_Printf ("Requesting snap from user %d...\n", uid); }
void SV_BeginDownload_f(void) { char *name; extern cvar_t allow_download; extern cvar_t allow_download_skins; extern cvar_t allow_download_models; extern cvar_t allow_download_sounds; extern cvar_t allow_download_maps; extern int file_from_pak; // ZOID did file come from pak? name = Cmd_Argv(1); // hacked by zoid to allow more conrol over download // first off, no .. or global allow check if (strstr (name, "..") || !allow_download.value // leading dot is no good || *name == '.' // leading slash bad as well, must be in subdir || *name == '/' // next up, skin check || (strncmp(name, "skins/", 6) == 0 && !allow_download_skins.value) // now models || (strncmp(name, "progs/", 6) == 0 && !allow_download_models.value) // now sounds || (strncmp(name, "sound/", 6) == 0 && !allow_download_sounds.value) // now maps (note special case for maps, must not be in pak) || (strncmp(name, "maps/", 6) == 0 && !allow_download_maps.value) // MUST be in a subdirectory || !strstr (name, "/") ) { // don't allow anything with .. path ClientReliableWrite_Begin (host_client, svc_download, 4); ClientReliableWrite_Short (host_client, -1); ClientReliableWrite_Byte (host_client, 0); return; } if (host_client->download) { fclose (host_client->download); host_client->download = NULL; } // lowercase name (needed for casesen file systems) { char *p; for (p = name; *p; p++) *p = (char)tolower(*p); } host_client->downloadsize = COM_FOpenFile (name, &host_client->download); host_client->downloadcount = 0; if (!host_client->download // special check for maps, if it came from a pak file, don't allow // download ZOID || (strncmp(name, "maps/", 5) == 0 && file_from_pak)) { if (host_client->download) { fclose(host_client->download); host_client->download = NULL; } Sys_Printf ("Couldn't download %s to %s\n", name, host_client->name); ClientReliableWrite_Begin (host_client, svc_download, 4); ClientReliableWrite_Short (host_client, -1); ClientReliableWrite_Byte (host_client, 0); return; } SV_NextDownload_f (); Sys_Printf ("Downloading %s to %s\n", name, host_client->name); }
void SV_NextUpload (void) { byte buffer[1024]; int r; int percent; int size; client_t *client; if (!*host_client->uploadfn) { SV_ClientPrintf(host_client, PRINT_HIGH, "Upload denied\n"); ClientReliableWrite_Begin (host_client, svc_stufftext, 8); ClientReliableWrite_String (host_client, "stopul"); // suck out rest of packet size = MSG_ReadShort (); MSG_ReadByte (); msg_readcount += size; return; } size = MSG_ReadShort (); percent = MSG_ReadByte (); if (!host_client->upload) { host_client->upload = fopen(host_client->uploadfn, "wb"); if (!host_client->upload) { Sys_Printf("Can't create %s\n", host_client->uploadfn); ClientReliableWrite_Begin (host_client, svc_stufftext, 8); ClientReliableWrite_String (host_client, "stopul"); *host_client->uploadfn = 0; return; } Sys_Printf("Receiving %s from %d...\n", host_client->uploadfn, host_client->userid); if (host_client->remote_snap) OutofBandPrintf(host_client->snap_from, "Server receiving %s from %d...\n", host_client->uploadfn, host_client->userid); } fwrite (net_message.data + msg_readcount, 1, size, host_client->upload); msg_readcount += size; Con_DPrintf ("UPLOAD: %d received\n", size); if (percent != 100) { ClientReliableWrite_Begin (host_client, svc_stufftext, 8); ClientReliableWrite_String (host_client, "nextul\n"); } else { fclose (host_client->upload); host_client->upload = NULL; Sys_Printf("%s upload completed.\n", host_client->uploadfn); if (host_client->remote_snap) { char *p; if ((p = strchr(host_client->uploadfn, '/')) != NULL) p++; else p = host_client->uploadfn; OutofBandPrintf(host_client->snap_from, "%s upload completed.\nTo download, enter:\ndownload %s\n", host_client->uploadfn, p); } } }
void SV_Begin_f (void) { unsigned pmodel = 0, emodel = 0; int i; if (host_client->state == cs_spawned) return; // don't begin again host_client->state = cs_spawned; // handle the case of a level changing while a client was connecting if ( atoi(Cmd_Argv(1)) != svs.spawncount ) { Con_Printf ("SV_Begin_f from different level\n"); SV_New_f (); return; } if (host_client->spectator) { SV_SpawnSpectator (); if (SpectatorConnect) { // copy spawn parms out of the client_t for (i=0 ; i< NUM_SPAWN_PARMS ; i++) (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i]; // call the spawn function pr_global_struct->time = sv.time; pr_global_struct->self = EDICT_TO_PROG(sv_player); PR_ExecuteProgram (SpectatorConnect); } } else { // copy spawn parms out of the client_t for (i=0 ; i< NUM_SPAWN_PARMS ; i++) (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i]; // call the spawn function pr_global_struct->time = sv.time; pr_global_struct->self = EDICT_TO_PROG(sv_player); PR_ExecuteProgram (pr_global_struct->ClientConnect); // actually spawn the player pr_global_struct->time = sv.time; pr_global_struct->self = EDICT_TO_PROG(sv_player); PR_ExecuteProgram (pr_global_struct->PutClientInServer); } // clear the net statistics, because connecting gives a bogus picture host_client->netchan.frame_latency = 0; host_client->netchan.frame_rate = 0; host_client->netchan.drop_count = 0; host_client->netchan.good_count = 0; //check he's not cheating pmodel = atoi(Info_ValueForKey (host_client->userinfo, "pmodel")); emodel = atoi(Info_ValueForKey (host_client->userinfo, "emodel")); if (pmodel != sv.model_player_checksum || emodel != sv.eyes_player_checksum) SV_BroadcastPrintf (PRINT_HIGH, "%s WARNING: non standard player/eyes model detected\n", host_client->name); // if we are paused, tell the client if (sv.paused) { ClientReliableWrite_Begin (host_client, svc_setpause, 2); ClientReliableWrite_Byte (host_client, sv.paused); SV_ClientPrintf(host_client, PRINT_HIGH, "Server is paused.\n"); } #if 0 // // send a fixangle over the reliable channel to make sure it gets there // Never send a roll angle, because savegames can catch the server // in a state where it is expecting the client to correct the angle // and it won't happen if the game was just loaded, so you wind up // with a permanent head tilt ent = EDICT_NUM( 1 + (host_client - svs.clients) ); MSG_WriteByte (&host_client->netchan.message, svc_setangle); for (i=0 ; i < 2 ; i++) MSG_WriteAngle (&host_client->netchan.message, ent->v.angles[i] ); MSG_WriteAngle (&host_client->netchan.message, 0 ); #endif }
void SV_Spawn_f (void) { int i; client_t *client; edict_t *ent; eval_t *val; int n; if (host_client->state != cs_connected) { Con_Printf ("Spawn not valid -- allready spawned\n"); return; } // handle the case of a level changing while a client was connecting if ( atoi(Cmd_Argv(1)) != svs.spawncount ) { Con_Printf ("SV_Spawn_f from different level\n"); SV_New_f (); return; } n = atoi(Cmd_Argv(2)); // make sure n is valid if ( n < 0 || n > MAX_CLIENTS ) { Con_Printf ("SV_Spawn_f invalid client start\n"); SV_New_f (); return; } // send all current names, colors, and frag counts // FIXME: is this a good thing? SZ_Clear (&host_client->netchan.message); // send current status of all other players // normally this could overflow, but no need to check due to backbuf for (i=n, client = svs.clients + n ; i<MAX_CLIENTS ; i++, client++) SV_FullClientUpdateToClient (client, host_client); // send all current light styles for (i=0 ; i<MAX_LIGHTSTYLES ; i++) { ClientReliableWrite_Begin (host_client, svc_lightstyle, 3 + (sv.lightstyles[i] ? strlen(sv.lightstyles[i]) : 1)); ClientReliableWrite_Byte (host_client, (char)i); ClientReliableWrite_String (host_client, sv.lightstyles[i]); } // set up the edict ent = host_client->edict; memset (&ent->v, 0, progs->entityfields * 4); ent->v.colormap = NUM_FOR_EDICT(ent); ent->v.team = 0; // FIXME ent->v.netname = PR_SetString(host_client->name); host_client->entgravity = 1.0; val = GetEdictFieldValue(ent, "gravity"); if (val) val->_float = 1.0; host_client->maxspeed = sv_maxspeed.value; val = GetEdictFieldValue(ent, "maxspeed"); if (val) val->_float = sv_maxspeed.value; // // force stats to be updated // memset (host_client->stats, 0, sizeof(host_client->stats)); ClientReliableWrite_Begin (host_client, svc_updatestatlong, 6); ClientReliableWrite_Byte (host_client, STAT_TOTALSECRETS); ClientReliableWrite_Long (host_client, pr_global_struct->total_secrets); ClientReliableWrite_Begin (host_client, svc_updatestatlong, 6); ClientReliableWrite_Byte (host_client, STAT_TOTALMONSTERS); ClientReliableWrite_Long (host_client, pr_global_struct->total_monsters); ClientReliableWrite_Begin (host_client, svc_updatestatlong, 6); ClientReliableWrite_Byte (host_client, STAT_SECRETS); ClientReliableWrite_Long (host_client, pr_global_struct->found_secrets); ClientReliableWrite_Begin (host_client, svc_updatestatlong, 6); ClientReliableWrite_Byte (host_client, STAT_MONSTERS); ClientReliableWrite_Long (host_client, pr_global_struct->killed_monsters); // get the client to check and download skins // when that is completed, a begin command will be issued ClientReliableWrite_Begin (host_client, svc_stufftext, 8); ClientReliableWrite_String (host_client, "skins\n" ); }