int com_ftell(int p, param_list param) { struct player *pp = &player_globals.parray[p]; int p1; char command[1024]; if (param[0].type == TYPE_WORD) { if ((p1 = player_find_part_login(param[0].val.word)) < 0) { pprintf(p, "%s isn't logged in.\n", param[0].val.word); return COM_OK; } if (p1 == p) { pprintf (p, "Nobody wants to listen to you talking to yourself! :-)\n"); return COM_OK; } if (pp->ftell != -1) { sprintf (command, "tell 0 I will no longer be forwarding the conversation between *%s* and myself.", player_globals.parray[pp->ftell].name); pcommand (p,command); } sprintf (command, "tell 0 I will be forwarding the conversation between *%s* and myself to channel 0.", player_globals.parray[p1].name); pcommand (p,command); pp->ftell = p1; return COM_OK_NOPROMPT; } else { if (pp->ftell != -1) { pprintf (p,"Stopping the forwarding of the conservation with %s.\n", player_globals.parray[pp->ftell].name); pcommand (p,"tell 0 I will no longer be forwarding the conversation between *%s* and myself.", player_globals.parray[pp->ftell].name); pp->ftell = -1; return COM_OK_NOPROMPT; } else pprintf (p,"You were not forwarding a conversation.\n"); } return COM_OK; }
/* * asetemail * * Usage: asetemail player [address] * * Sets the email address of the player to the address given. If the * address is omited, then the player's email address is cleared. The * person's email address is revealed to them when they use the "finger" * command, but no other users -- except admins -- will have another * player's email address displayed. */ int com_asetemail(int p, param_list param) { struct player *pp = &player_globals.parray[p]; int p1, connected; char *oldemail; if (!FindPlayer(p, param[0].val.word, &p1, &connected)) return COM_OK; if (!check_admin2(p, p1)) { pprintf(p, "You can only set email addr for players below your adminlevel.\n"); if (!connected) player_remove(p1); return COM_OK; } if (player_globals.parray[p1].emailAddress) { oldemail = strdup(player_globals.parray[p1].emailAddress); free(player_globals.parray[p1].emailAddress); } else { oldemail = strdup(""); } if (param[1].type == TYPE_NULL) { player_globals.parray[p1].emailAddress = NULL; pprintf(p, "Email address for %s removed\n", player_globals.parray[p1].name); pcommand(p, "addcomment %s Email address removed.\n", player_globals.parray[p1].name); } else { player_globals.parray[p1].emailAddress = strdup(param[1].val.word); pprintf(p, "Email address of %s changed to \"%s\".\n", player_globals.parray[p1].name, param[1].val.word); pcommand(p, "addcomment %s Email address changed from %s to %s.\n", player_globals.parray[p1].name, oldemail, player_globals.parray[p1].emailAddress); } free(oldemail); player_save(p1); if (connected) { if (param[1].type == TYPE_NULL) { pprintf_prompt(p1, "\n\n%s has removed your email address.\n\n", pp->name); } else { pprintf_prompt(p1, "\n\n%s has changed your email address.\n\n", pp->name); } } else { player_remove(p1); } return COM_OK; }
/* * asetpasswd * * Usage: asetpasswd player {password,*} * * This command sets the password of the player to the password given. * If '*' is specified then the player's account is locked, and no password * will work until a new one is set by asetpasswd. * * If the player is connected, he is told of the new password and the name * of the admin who changed it, or likewise of his account status. An * email message is mailed to the player's email address as well. */ int com_asetpasswd(int p, param_list param) { struct player *pp = &player_globals.parray[p]; int p1, connected; char subject[400], text[10100]; char salt[3]; if (!FindPlayer(p, param[0].val.word, &p1, &connected)) return COM_OK; if (!check_admin2(p, p1)) { pprintf(p, "You can only set password for players below your adminlevel.\n"); if (!connected) player_remove(p1); return COM_OK; } if (!CheckPFlag(p1, PFLAG_REG)) { pprintf(p, "You cannot set the password of an unregistered player!\n"); return COM_OK; } if (player_globals.parray[p1].passwd) free(player_globals.parray[p1].passwd); if (param[1].val.word[0] == '*') { player_globals.parray[p1].passwd = strdup(param[1].val.word); pprintf(p, "Account %s locked!\n", player_globals.parray[p1].name); sprintf(text, "Password of %s is now useless. Your account at our" " BICS has been locked.\n", player_globals.parray[p1].name); pprintf(p, "Please leave a comment to explain why %s's account" " was locked.\n", player_globals.parray[p1].name); pcommand(p, "addcomment %s Account locked.\n", player_globals.parray[p1].name); } else { salt[0] = 'a' + random() % 26; salt[1] = 'a' + random() % 26; salt[2] = '\0'; player_globals.parray[p1].passwd = strdup(chessd_crypt(param[1].val.word, salt)); sprintf(text, "Password of %s changed to \"%s\".\n", player_globals.parray[p1].name, param[1].val.word); pprintf(p, "%s", text); } if (param[1].val.word[0] == '*') { sprintf(subject, "CHESSD: %s has locked your account.", pp->name); if (connected) pprintf_prompt(p1, "\n%s\n", subject); } else { sprintf(subject, "CHESSD: %s has changed your password.", pp->name); if (connected) pprintf_prompt(p1, "\n%s\n", subject); } mail_string_to_address(player_globals.parray[p1].emailAddress, subject, text); player_save(p1); if (!connected) player_remove(p1); return COM_OK; }
//********************************************************************************************************************** vector<string> SystemCommand::setParameters(){ try { CommandParameter pcommand("command", "String", "", "", "", "", "",false,false); parameters.push_back(pcommand); vector<string> myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { m->errorOut(e, "SystemCommand", "setParameters"); exit(1); } }
/* * asetv * * Usage: asetv user instructions * * This command executes "set" instructions as if they had been made by the * user indicated. For example, "asetv DAV shout 0" would set DAV's shout * variable to 0. */ int com_asetv(int p, param_list param) { int p1; if ((p1 = player_find_part_login(param[0].val.word)) < 0) { pprintf(p, "%s is not logged in.\n", param[0].val.word); return COM_OK; } //bad realisation if (in_list(p, L_TD, player_globals.parray[p].name)) { pprintf(p, "Command issued as %s\n", player_globals.parray[p1].name); pcommand(p1, "set %s\n", param[1].val.string); return COM_OK; } if (!check_admin2(p, p1)) { pprintf(p, "You can only aset players below your adminlevel.\n"); return COM_OK; } pprintf(p, "Command issued as %s\n", player_globals.parray[p1].name); pcommand(p1, "set %s\n", param[1].val.string); return COM_OK; }
int com_pose(int p, param_list param) { int p1; if ((p1 = player_find_part_login(param[0].val.word)) < 0) { pprintf(p, "%s is not logged in.\n", param[0].val.word); return COM_OK; } if (!check_admin2(p, p1)) { pprintf(p, "You can only pose as players below your adminlevel.\n"); return COM_OK; } pprintf(p, "Command issued as %s\n", player_globals.parray[p1].name); pcommand(p1, "$$%s\n", param[1].val.string); return COM_OK; }
void command_mode(void) { char buf[256], *p; terminal_mode(TERMINAL_COOKED); printf("\n" "pconsole command mode\n" ">>> "); fflush(stdout); flags |= FLAGS_CMD_MODE; while((p = fgets(buf, 256, stdin)) != NULL) { cstrip_line(buf); if (*buf) pcommand(buf); if (flags & FLAGS_CMD_MODE) { if (*buf) printf("\n"); printf(">>> "); fflush(stdout); } else break; } if (p == NULL) { if (AllConns == NULL) { printf("\n\n"); terminal_mode(TERMINAL_COOKED); exit(0); } else printf("<Ctrl-D>\n"); } flags &= ~FLAGS_CMD_MODE; printf("\n" "Press <Ctlr-A> for command mode\n" "> "); fflush(stdout); terminal_mode(TERMINAL_RAW); }
/* rmatch is used by tournament bots to start matches in tournaments */ int com_rmatch(int p, param_list param) { struct player *pp = &player_globals.parray[p]; int p1, p2; if (!in_list(p, L_TD, pp->name)) { pprintf(p, "Only TD programs are allowed to use this command.\n"); return COM_OK; } if ((p1 = player_find_bylogin(param[0].val.word)) < 0) { /* can't rmatch this user ... */ return COM_OK; } if ((p2 = player_find_bylogin(param[1].val.word)) < 0) { /* can't rmatch this user ... */ return COM_OK; } return pcommand(p1, "$$ match %s %s", param[1].val.word, param[2].val.string); }
/* rematch */ int com_rematch(int p, param_list param) { struct player *pp = &player_globals.parray[p]; if (!pp->last_opponent) { pprintf (p,"There is no last game for you.\n"); } else if (strcmp(pp->last_board, "") && strcmp(pp->last_board,"FR")) { pprintf (p,"Your last game was non standard. Please specify it by yourself.\n"); } else { pcommand(p,"match %s %d %d %s %s %s", pp->last_opponent, pp->last_time/60, pp->last_inc, pp->last_rated ? "r" : "u", pp->last_category, pp->last_board); } return COM_OK; }
/* * nuke * * Usage: nuke user * * This command disconnects the user from the server. The user is informed * that she/he has been nuked by the admin named and a comment is * automatically placed in the user's files (if she/he is a registered * user, of course). */ int com_nuke(int p, param_list param) { struct player *pp = &player_globals.parray[p]; int p1, fd; if ((p1 = player_find_part_login(param[0].val.word)) < 0) { pprintf(p, "%s isn't logged in.\n", param[0].val.word); return COM_OK; } if (!check_admin2(p, p1)) { pprintf(p, "You need a higher adminlevel to nuke %s!\n", param[0].val.word); return COM_OK; } pprintf(p, "Nuking: %s\n", param[0].val.word); pprintf(p, "Please leave a comment explaining why %s was nuked.\n", player_globals.parray[p1].name); pprintf(p1, "\n\n**** You have been kicked out by %s! ****\n\n", pp->name); if (CheckPFlag(p1, PFLAG_REG)) pcommand(p, "addcomment %s Nuked\n", player_globals.parray[p1].name); /* addcomment doesnt work on guests */ fd = player_globals.parray[p1].socket; process_disconnection(fd); net_close_connection(fd); return COM_OK; }
/* * adjudicate * * Usage: adjudicate white_player black_player result * * Adjudicates a saved (stored) game between white_player and black_player. * The result is one of: abort, draw, white, black. "Abort" cancels the game * (no win, loss or draw), "white" gives white_player the win, "black" gives * black_player the win, and "draw" gives a draw. */ int com_adjudicate(int p, param_list param) { int wp, wconnected, bp, bconnected, g, inprogress, confused = 0; if (!FindPlayer(p, param[0].val.word, &wp, &wconnected)) return COM_OK; if (!FindPlayer(p, param[1].val.word, &bp, &bconnected)) { if (!wconnected) player_remove(wp); return COM_OK; } inprogress = ((player_globals.parray[wp].game >=0) &&(player_globals.parray[wp].opponent == bp)); if (inprogress) { g = player_globals.parray[wp].game; } else { g = game_new(); if (game_read(g, wp, bp) < 0) { confused = 1; pprintf(p, "There is no stored game %s vs. %s\n", player_globals.parray[wp].name, player_globals.parray[bp].name); } else { game_globals.garray[g].white = wp; game_globals.garray[g].black = bp; } } if (!confused) { if (strstr("abort", param[2].val.word) != NULL) { game_ended(g, WHITE, END_ADJABORT); pcommand(p, "message %s Your game \"%s vs. %s\" has been aborted.", player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name); pcommand(p, "message %s Your game \"%s vs. %s\" has been aborted.", player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name); } else if (strstr("draw", param[2].val.word) != NULL) { game_ended(g, WHITE, END_ADJDRAW); pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated " "as a draw", player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name); pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated " "as a draw", player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name); } else if (strstr("white", param[2].val.word) != NULL) { game_ended(g, WHITE, END_ADJWIN); pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated " "as a win", player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name); pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated " "as a loss", player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name); } else if (strstr("black", param[2].val.word) != NULL) { game_ended(g, BLACK, END_ADJWIN); pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated " "as a loss", player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name); pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated " "as a win", player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name); } else { confused = 1; pprintf(p, "Result must be one of: abort draw white black\n"); } } if (!confused) { pprintf(p, "Game adjudicated.\n"); if (!inprogress) { game_delete(wp, bp); } else { return (COM_OK); } } game_remove(g); if (!wconnected) player_remove(wp); if (!bconnected) player_remove(bp); return COM_OK; }
/* add or subtract something to/from a list */ int list_addsub(int p, char* list, char* who, int addsub) { struct player *pp = &player_globals.parray[p]; int p1, connected, loadme, personal, ch; char *listname, *member, junkChar; struct List *gl; char *yourthe, *addrem; gl = list_findpartial(p, list, addsub); if (!gl) return COM_OK; personal = ListArray[gl->which].rights == P_PERSONAL; loadme = (gl->which != L_FILTER) && (gl->which != L_REMOVEDCOM) && (gl->which != L_CHANNEL); listname = ListArray[gl->which].name; yourthe = personal ? "your" : "the"; addrem = (addsub == 1) ? "added to" : "removed from"; if (loadme) { if (!FindPlayer(p, who, &p1, &connected)) { if (addsub == 1) return COM_OK; member = who; /* allow sub removed/renamed player */ loadme = 0; } else member = player_globals.parray[p1].name; } else { member = who; } if (addsub == 1) { /* add to list */ if (gl->which == L_CHANNEL) { if (sscanf (who,"%d%c",&ch, &junkChar) == 1 && ch >= 0 && ch < 255) { if ((ch == 0) && (!in_list(p,L_ADMIN,pp->name))) { pprintf(p, "Only admins may join channel 0.\n"); return COM_OK; } } else { pprintf (p,"The channel to add must be a number between 0 and %d.\n",MAX_CHANNELS - 1); return COM_OK; } } if (in_list(p, gl->which, member)) { pprintf(p, "[%s] is already on %s %s list.\n", member, yourthe, listname); if (loadme && !connected) player_remove(p1); return COM_OK; } if (list_add(p, gl->which, member)) { pprintf(p, "Sorry, %s %s list is full.\n", yourthe, listname); if (loadme && !connected) player_remove(p1); return COM_OK; } } else if (addsub == 2) { /* subtract from list */ if (!in_list(p, gl->which, member)) { pprintf(p, "[%s] is not in %s %s list.\n", member, yourthe, listname); if (loadme && !connected) player_remove(p1); return COM_OK; } list_sub(p, gl->which, member); } pprintf(p, "[%s] %s %s %s list.\n", member, addrem, yourthe, listname); if (!personal) { FILE *fp; char filename[MAX_FILENAME_SIZE]; switch (gl->which) { case L_MUZZLE: case L_CMUZZLE: case L_C1MUZZLE: case L_C24MUZZLE: case L_C46MUZZLE: case L_C49MUZZLE: case L_C50MUZZLE: case L_C51MUZZLE: case L_ABUSER: case L_BAN: case L_NOTEBAN: case L_RATEBAN: pprintf(p, "Please leave a comment to explain why %s was %s the %s list.\n", member, addrem, listname); pcommand(p, "addcomment %s %s %s list.\n", member, addrem, listname); break; case L_COMPUTER: /*if (player_globals.parray[p1].z_stats.rating > 0) UpdateRank(TYPE_CRAZYHOUSE, member, &player_globals.parray[p1].z_stats, member); if (player_globals.parray[p1].s_stats.rating > 0) UpdateRank(TYPE_STAND, member, &player_globals.parray[p1].s_stats, member); if (player_globals.parray[p1].w_stats.rating > 0) UpdateRank(TYPE_WILD, member, &player_globals.parray[p1].w_stats, member);*/ break; case L_ADMIN: if (addsub == 1) { /* adding to list */ player_globals.parray[p1].adminLevel = 10; pprintf(p, "%s has been given an admin level of 10 - change with asetadmin.\n", member); } else { player_globals.parray[p1].adminLevel = 0; } break; case L_FILTER: case L_REMOVEDCOM: default: break; } if (loadme && connected) pprintf_prompt(p1, "You have been %s the %s list by %s.\n", addrem, listname, pp->name); sprintf(filename, "%s/%s", LISTS_DIR, listname); fp = fopen_s(filename, "w"); if (fp == NULL) { d_printf( "Couldn't save %s list.\n", listname); } else { int i; for (i = 0; i < gl->numMembers; i++) fprintf(fp, "%s\n", gl->m_member[i]); fclose(fp); } } if (loadme || (gl->which == L_ADMIN)) { player_save(p1); } if (loadme && !connected) { player_remove(p1); } return COM_OK; }