void clientmessage(XEvent *e) { XClientMessageEvent *ev = &e->xclient; Client *c; if (ev->message_type == atom[CloseWindow]) { if ((c = getclient(ev->window, clients, ClientWindow))) killclient(c); } else if (ev->message_type == atom[ActiveWindow]) { if ((c = getclient(ev->window, clients, ClientWindow))) { c->isicon = False; focus(c); arrange(curmonitor()); } } else if (ev->message_type == atom[CurDesk]) { view(tags[ev->data.l[0]]); } else if (ev->message_type == atom[WindowState]) { if ((c = getclient(ev->window, clients, ClientWindow))) { ewmh_process_state_atom(c, (Atom) ev->data.l[1], ev->data.l[0]); if (ev->data.l[2]) ewmh_process_state_atom(c, (Atom) ev->data.l[2], ev->data.l[0]); } } else if (ev->message_type == atom[WMChangeState]) { if ((c = getclient(ev->window, clients, ClientWindow))) { if (ev->data.l[0] == IconicState) { focus(c); iconify(NULL); } } } }
void SV_BanNum_f( void ) { if(!sv_running->integer ) { Com_Printf("Server is not running.\n"); return; } if(Cmd_Argc()!=4) { Com_Printf("Usage: %s <id> \"reason\" \"guid|ip\"\n", Cmd_Argv(0)); return; } client_t* cl = getclient(atoi(Cmd_Argv(1))); if(!cl->state) { Com_Printf("Client is not active.\n"); return; } char* reason = Cmd_Argv(2); if(!*reason) reason = "No reason."; char* bantypestr = Cmd_Argv(3); int bantype = IPBAN; if(!strcmp(bantypestr, "guid")) bantype = GUIDBAN; SV_BanProcess(cl, bantype, reason); }
fpsent *followingplayer() { if(player1->state!=CS_SPECTATOR || following<0) return NULL; fpsent *target = getclient(following); if(target && target->state!=CS_SPECTATOR) return target; return NULL; }
void SV_BanGUID_f() { if(Cmd_Argc()!=2) { Com_Printf("Usage: banguid <guid>\n"); return; } int guid = atoi( Cmd_Argv(1) ); if(guid == 0 && !x_authorize->integer) { Com_Printf("Error: You can't ban GUID zero.\n"); return; } client_t* cl; for(int i = 0; i < sv_maxclients->integer; i++) { cl=getclient(i); if(!cl->state) continue; if(CL_GetGuid(cl) == guid) { SV_DropClient(cl, "banned"); break; } } FILE* f = fopen("guidbans.txt", "a"); if(f) { fprintf(f, "%d\n", guid); fclose(f); } Com_Printf("GUID '%d' has been banned.\n", guid); X_ReadBannedList(false); }
void servuser::execkill(char **array, int count) { if (count<6) return; client *c=getclient(array[4]); if (!c) return; clientinterface->handlekill(c, array[5]); }
void SV_BanIP_f() { if(Cmd_Argc()!=2) { Com_Printf("Usage: banip <ip>\n"); return; } char* ip = Cmd_Argv(1); netadr_t adr; NET_StringToAdr(ip, &adr); client_t* cl; for(int i = 0; i < sv_maxclients->integer; i++) { cl=getclient(i); if(!cl->state) continue; if(NET_CompareBaseAdr(adr, cl->remoteAddress)) { SV_DropClient(cl, "banned"); break; } } FILE* f = fopen("ipbans.txt", "a"); if(f) { fprintf(f,"%s\n",ip); fclose(f); } Com_Printf("IP '%s' has been banned.\n", ip); X_ReadBannedList(false); }
void SVC_Info( netadr_t* from ) { int i, count; char *gamedir; char infostring[MAX_INFO_STRING]; char* g_password; if ( !SV_VerifyChallenge( Cmd_Argv( 1 ) ) ) { return; } g_password = Cvar_VariableString("g_password"); // don't count privateclients count = 0; for ( i = sv_privateClients->integer ; i < sv_maxclients->integer ; i++ ) { if ( getclient(i)->state >= CS_CONNECTED ) { count++; } } infostring[0] = 0; // echo back the parameter to status. so servers can use it as a challenge // to prevent timed spoofed reply packets that add ghost servers Info_SetValueForKey( infostring, "challenge", Cmd_Argv( 1 ) ); Info_SetValueForKey( infostring, "protocol", va("%i", protocol->integer)); Info_SetValueForKey( infostring, "hostname", sv_hostname->string ); Info_SetValueForKey( infostring, "mapname", mapname->string ); Info_SetValueForKey( infostring, "clients", va( "%i", count ) ); #ifdef xDEBUG Info_SetValueForKey( infostring, "sv_maxclients", va( "%i", sv_maxclients->integer - sv_privateClients->integer ) ); #else Info_SetValueForKey( infostring, "sv_maxclients", va( "%i", sv_maxclients->integer - sv_privateClients->integer ) ); #endif Info_SetValueForKey( infostring, "gametype", g_gametype->string ); Info_SetValueForKey( infostring, "pure", va( "%i", sv_pure->integer ) ); Info_SetValueForKey(infostring, "codextended", va("v%d", CURRENTBUILD)); if ( sv_minPing->integer ) { Info_SetValueForKey( infostring, "minPing", va( "%i", sv_minPing->integer ) ); } if ( sv_maxPing->integer ) { Info_SetValueForKey( infostring, "maxPing", va( "%i", sv_maxPing->integer ) ); } gamedir = Cvar_VariableString( "fs_game" ); if ( *gamedir ) { Info_SetValueForKey( infostring, "game", gamedir ); } Info_SetValueForKey( infostring, "sv_allowAnonymous", va( "%i", sv_allowAnonymous->integer ) ); if(*g_password) Info_SetValueForKey( infostring, "pswrd", "1"); else Info_SetValueForKey( infostring, "pswrd", "0"); NET_OutOfBandPrint( NS_SERVER, *from, "infoResponse\n%s", infostring ); }
void servuser::execad(char **array, int count) { if (count<12) return; client *who=getclient(array[4]); if (!who) return; who->updateatc(array+5); clientinterface->sendatcpos(who, NULL); }
void servuser::execpd(char **array, int count) { if (count<14) return; client *who=getclient(array[5]); if (!who) return; who->updatepilot(array+4); clientinterface->sendpilotpos(who, NULL); }
static void unmapnotify(XEvent *e) { Client *c; XUnmapEvent *ev = &e->xunmap; if((c = getclient(ev->window))) unmanage(c); }
static void destroynotify(XEvent *e) { Client *c; XDestroyWindowEvent *ev = &e->xdestroywindow; if((c = getclient(ev->window))) unmanage(c); }
void SVC_Status( netadr_t* from ) { char player[1024]; char status[MAX_MSGLEN]; int i; client_t *cl; int/*playerState_t*/ *ps; int statusLength; int playerLength; char infostring[MAX_INFO_STRING]; int custom_mod = 0; char *fs_game = Cvar_VariableString("fs_game"); if(fs_game && *fs_game) custom_mod = 1; challenge_t* challenge; if ( !SV_VerifyChallenge( Cmd_Argv( 1 ) ) ) { return; } strcpy( infostring, Cvar_InfoString( 4 )); //1.5 uses 8196 Info_SetValueForKey( infostring, "challenge", Cmd_Argv( 1 ) ); status[0] = 0; statusLength = 0; for ( i = 0 ; i < sv_maxclients->integer ; i++ ) { cl = getclient(i); if ( cl->state >= CS_CONNECTED ) { //ps = SV_GameClientNum( i ); Com_sprintf( player, sizeof( player ), "%i %i \"%s\"\n", SV_GetClientScore(cl), cl->ping, cl->name ); playerLength = strlen( player ); if ( statusLength + playerLength >= sizeof( status ) ) { break; // can't hold any more } strcpy( status + statusLength, player ); statusLength += playerLength; } } #if CODPATCH == 5 if(sv_disableClientConsole->integer) Info_SetValueForKey(infostring, "con_disabled", va("%i", sv_disableClientConsole->integer)); #endif char *g_password = Cvar_VariableString("g_password"); Info_SetValueForKey(infostring, "pswrd", va("%i", (g_password && *g_password) ? 1 : 0)); Info_SetValueForKey(infostring, "mod", va("%i", custom_mod)); NET_OutOfBandPrint( NS_SERVER, *from, "statusResponse\n%s\n%s", infostring, status ); }
Client * selectwin(int release, int *shift, ScreenInfo *s) { XEvent ev; XButtonEvent *e; int status; Window w; Client *c; status = grab(s->root, s->root, ButtonMask, s->target, 0); if(status != GrabSuccess){ graberror("selectwin", status); /* */ return 0; } w = None; for(;;){ XMaskEvent(dpy, ButtonMask, &ev); e = &ev.xbutton; switch (ev.type){ case ButtonPress: if(e->button != Button3){ ungrab(e); return 0; } w = e->subwindow; if(!release){ c = getclient(w, 0); if(c == 0) ungrab(e); if(shift != 0) *shift = (e->state&ShiftMask) != 0; return c; } break; case ButtonRelease: ungrab(e); if(e->button != Button3 || e->subwindow != w) return 0; if(shift != 0) *shift = (e->state&ShiftMask) != 0; return getclient(w, 0); } } }
void startdemo() { democlientnum = gzgeti(); demoplayback = true; starttime = lastmillis; conoutf("now playing demo"); Sprite *d = getclient(democlientnum); assert(d); *d = *player1; readdemotime(); }
void servuser::execmetar(char **array, int count) { if (count<7) return; int fd=atoi(array[5]); if (fd!=-1) systeminterface->receivemetar(fd, array[4], array[6]); else { client *c=getclient(array[0]+1); if (!c) return; clientinterface->sendmetar(c, array[6]); } }
void servuser::execnowx(char **array, int count) { if (count<6) return; int fd=atoi(array[5]); if (fd==-1) { client *c=getclient(array[0]+1); if (!c) return; clientinterface->sendnowx(c, array[4]); } else systeminterface->receivenowx(fd, array[4]); }
static void maprequest(XEvent *e) { static XWindowAttributes wa; XMapRequestEvent *ev = &e->xmaprequest; if(!XGetWindowAttributes(dpy, ev->window, &wa)) return; if(wa.override_redirect) return; if(!getclient(ev->window)) manage(ev->window, &wa); }
int servuser::execplan(char **array, int count) { if (count<21) return 0; int revision=atoi(array[5]); client *who=getclient(array[4]); if (!who) return 1; if (who->plan&&who->plan->revision>=revision) return 0; who->handlefp(array+6); who->plan->revision=revision; clientinterface->sendplan(NULL, who, 400); return 1; }
void servuser::execmulticast(char **array, int count) { char *dest; if (count<7) return; client *c=NULL, *source=getclient(array[5]); int cmd=atoi(array[4]); if (cmd > CL_MAX) return; switch (*array[0]) { case '*' : case '@': dest=array[0]; break; default: c=getclient(array[0]+1); if (!c) return; dest=array[0]+1; break; } char buf[1000]; clientinterface->sendgeneric(dest, c, NULL, source, array[5], catcommand(array+6, count-6, buf), cmd); }
/* Handle an RM CLIENT packet */ void servuser::execrmclient(char **array, int count) { if (count<5) return; client *c=getclient(array[4]); if (c) { int type=c->type; if (c->location==myserver) return; if (type==CLIENT_ATC) clientinterface->sendda(c, NULL); else if (type==CLIENT_PILOT) clientinterface->senddp(c, NULL); delete c; } }
void servuser::execweather(char **array, int count) { if (count<56) return; wprofile prof(array[4], 0, NULL); int fd=atoi(array[5]); prof.loadarray(array+6, count-6); if (fd==-1) { client *c=getclient(array[0]+1); if (!c) return; clientinterface->sendweather(c, &prof); } else systeminterface->receiveweather(fd, &prof); }
void band_test() { int argc = Cmd_Argc(); if(argc != 3) { printf("Error\n"); return; } int index = 0; if(index < 0 || index >= sv_maxclients->integer) { printf("Error, wrong index.\n"); return; } client_t* cl = getclient(index); NET_OutOfBandPrint( NS_SERVER, cl->remoteAddress, Cmd_Argv(2)); }
static void configurerequest(XEvent *e) { unsigned long newmask; Client *c; XConfigureRequestEvent *ev = &e->xconfigurerequest; XWindowChanges wc; if((c = getclient(ev->window))) { c->ismax = False; if(ev->value_mask & CWX) c->x = ev->x; if(ev->value_mask & CWY) c->y = ev->y; if(ev->value_mask & CWWidth) c->w = ev->width; if(ev->value_mask & CWHeight) c->h = ev->height; if(ev->value_mask & CWBorderWidth) c->border = ev->border_width; wc.x = c->x; wc.y = c->y; wc.width = c->w; wc.height = c->h; newmask = ev->value_mask & (~(CWSibling | CWStackMode | CWBorderWidth)); if(newmask) XConfigureWindow(dpy, c->win, newmask, &wc); else configure(c); XSync(dpy, False); if(c->isfloat) { resize(c, False); if(c->view != view) XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); } else arrange(); } else { wc.x = ev->x; wc.y = ev->y; wc.width = ev->width; wc.height = ev->height; wc.border_width = ev->border_width; wc.sibling = ev->above; wc.stack_mode = ev->detail; XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); XSync(dpy, False); } }
void manage(Window w, XWindowAttributes *wa) { Client *c, *t; Window trans; c = emallocz(sizeof(Client)); c->win = w; c->x = wa->x; c->y = wa->y; c->w = wa->width; c->h = wa->height; if(c->w == sw && c->h == sh) { c->border = 0; c->x = sx; c->y = sy; } else { c->border = BORDERPX; if(c->x + c->w + 2 * c->border > sx + sw) c->x = sx + sw - c->w - 2 * c->border; if(c->y + c->h + 2 * c->border > sy + sh) c->y = sy + sh - c->h - 2 * c->border; if(c->x < sx) c->x = sx; if(c->y < sy) c->y = sy; } updatesizehints(c); XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); XGetTransientForHint(dpy, c->win, &trans); XSetWindowBorder(dpy, c->win, normcol); updatetitle(c); if((t = getclient(trans))) c->view = t->view; else c->view = view; if(clients) clients->prev = c; c->next = clients; c->snext = stack; stack = clients = c; XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); XMapWindow(dpy, c->win); setclientstate(c, NormalState); if(c->view == view) focus(c); arrange(); }
static void enternotify(XEvent *e) { Client *c; XCrossingEvent *ev = &e->xcrossing; if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) return; if((c = getclient(ev->window)) && c->view == view) focus(c); else if(ev->window == root) { selscreen = True; for(c = stack; c && c->view != view; c = c->snext); focus(c); } }
void *WebServer_Listen(void *arg) { int client_fd; struct sockaddr_in client_addr; socklen_t sin_len = sizeof(client_addr); char string[1024] = {0}; int send_len, i; while(bServRunning) { client_fd = accept(server_sock, (struct sockaddr*)&client_addr, &sin_len); cprintf(PRINT_GOOD, "Got connection on webserver.\n"); if(client_fd == -1) { cprintf(PRINT_ERR | PRINT_UNDERLINE, "Error: Couldn't accept.\n"); goto exthr; } *r_contents = 0; Com_sprintf(r_contents, sizeof(r_contents), "%s", responseHeader); /* add the html header etc */ Q_strcat(r_contents, sizeof(r_contents), "Webserver info CoDExtended (v20)<br />Players on server<br />"); client_t *cl; for(i = 0; i < sv_maxclients->integer; i++) { cl = getclient(i); if(cl->state >= CS_CONNECTED) { string[0] = '\0'; Com_sprintf(string, sizeof(string), "%d: %s<br />", get_client_number(cl), cl->name); Q_strcat(r_contents, sizeof(r_contents), string); } } send_len = strlen(r_contents); write(client_fd, r_contents, send_len); close(client_fd); } exthr: bServRunning = false; return NULL; }
/* Handle an ADD CLIENT packet */ int servuser::execaddclient(char **array, int count) { int type; client *c; if (count<12) return 1; server *location=getserver(array[5]); /* If we can't find the server, or the indicated server is our server, we don't need the new client. */ if (!location||location==myserver) return 1; type=atoi(array[7]); c=getclient(array[6]); if (c) return 0; c=new client(array[4],location,array[6],type,atoi(array[8]), array[9], array[10], atoi(array[11])); if (type==CLIENT_ATC) clientinterface->sendaa(c, NULL); else if (type==CLIENT_PILOT) clientinterface->sendap(c, NULL); return 1; }
void loadgamerest() { if (demoplayback || !f) return; if (gzgeti() != entityList.size()) return loadgameout(); for(Entity &en : entityList) { en.spawned = gzgetc(f) != 0; if (en.type == CARROT && !en.spawned) trigger(en.attr1, en.attr2, true); }; restoreserverstate(entityList); gzread(f, player1, sizeof(Sprite)); player1->lastaction = lastmillis; int nmonsters = gzgeti(); std::vector<Sprite *> &monsters = getmonsters(); if (nmonsters != monsters.size()) return loadgameout(); loopv(monsters) { gzread(f, monsters[i], sizeof(Sprite)); monsters[i]->enemy = player1; // lazy, could save id of enemy instead monsters[i]->lastaction = monsters[i]->trigger = lastmillis + 500; // also lazy, but no real noticable effect on game if (monsters[i]->state == CS_DEAD) monsters[i]->lastaction = 0; }; restoremonsterstate(); int nplayers = gzgeti(); loopi(nplayers) if (!gzget()) { Sprite *d = getclient(i); assert(d); gzread(f, d, sizeof(Sprite)); }; conoutf("savegame restored"); if (demoloading) startdemo(); else stop(); }
static void buttonpress(XEvent *e) { Client *c; XButtonPressedEvent *ev = &e->xbutton; if((c = getclient(ev->window))) { focus(c); if(CLEANMASK(ev->state) != MODKEY) return; if(ev->button == Button1 && c->isfloat) { restack(); movemouse(c); } else if(ev->button == Button2) zoom(NULL); else if(ev->button == Button3 && c->isfloat && !c->isfixed) { restack(); resizemouse(c); } } }
void X_GetPlayersByName( void ) { client_t *cl; int i; char *s; char cleanName[64]; for(unsigned int p; p < 64; p++) search_players[p] = NULL; if (!sv_running->integer ) return; if ( Cmd_Argc() < 2 ) { Com_Printf( "No substring given to search for.\n" ); return; } s = Cmd_Argv( 1 ); sv_listmsg = false; for ( i = 0 ; i < sv_maxclients->integer ; i++) { cl = getclient(i); if (!cl->state) continue; if ( strstr( cl->name, s ) ) { SV_WasAdded(s, i, cl->name); search_players[i] = cl; continue; } Q_strncpyz( cleanName, cl->name, sizeof( cleanName ) ); Q_CleanStr( cleanName ); if ( strstr( cleanName, s ) ) { search_players[i] = cl; SV_WasAdded(s, i, cl->name); } } }