/* * asethandle * * Usage: asethandle oldname newname * * This command changes the handle of the player from oldname to * newname. The various player information, messages, logins, comments * and games should be automatically transferred to the new account. */ int com_asethandle(int p, param_list param) { char *player = param[0].val.word; char *newplayer = param[1].val.word; char playerlower[MAX_LOGIN_NAME], newplayerlower[MAX_LOGIN_NAME]; int p1; strcpy(playerlower, player); stolower(playerlower); strcpy(newplayerlower, newplayer); stolower(newplayerlower); if (player_find_bylogin(playerlower) >= 0) { pprintf(p, "A player by that name is logged in.\n"); return COM_OK; } if (player_find_bylogin(newplayerlower) >= 0) { pprintf(p, "A player by that new name is logged in.\n"); return COM_OK; } p1 = player_new(); if (player_read(p1, playerlower)) { pprintf(p, "No player by the name %s is registered.\n", player); player_remove(p1); return COM_OK; } else { if (!check_admin2(p, p1)) { pprintf(p, "You can't set handles for an admin with a level higher than or equal to yourself.\n"); player_remove(p1); return COM_OK; } } player_remove(p1); p1 = player_new(); if ((!player_read(p1, newplayerlower)) && (strcmp(playerlower, newplayerlower))) { pprintf(p, "Sorry that handle is already taken.\n"); player_remove(p1); return COM_OK; } player_remove(p1); if ((!player_rename(playerlower, newplayerlower)) && (!player_read(p1, newplayerlower))) { pprintf(p, "Player %s renamed to %s.\n", player, newplayer); free(player_globals.parray[p1].name); player_globals.parray[p1].name = strdup(newplayer); player_save(p1); /*if (player_globals.parray[p1].s_stats.rating > 0) UpdateRank(TYPE_STAND, newplayer, &player_globals.parray[p1].s_stats, player); if (player_globals.parray[p1].z_stats.rating > 0) UpdateRank(TYPE_CRAZYHOUSE, newplayer, &player_globals.parray[p1].z_stats, player); if (player_globals.parray[p1].w_stats.rating > 0) UpdateRank(TYPE_WILD, newplayer, &player_globals.parray[p1].w_stats, player);*/ } else { pprintf(p, "Asethandle failed.\n"); } player_remove(p1); return COM_OK; }
/** * @brief Function to active the new game menu. * @param str Unused. */ static void menu_main_new( unsigned int wid, char* str ) { (void) str; (void) wid; menu_main_close(); player_new(); }
/** * @brief Restart the game, when player want to continue after death but without a savegame */ static void menu_death_restart( unsigned int wid, char* str ) { (void) str; window_destroy( wid ); menu_Close(MENU_DEATH); player_new(); }
/** * @brief Restart the game, when player want to continue after death but without a savegame */ static void menu_death_restart( unsigned int wid, char* str ) { (void) str; window_destroy( wid ); menu_Close(MENU_DEATH); if (player_isTut()) player_newTutorial(); else player_new(); }
int main( int argc, char** argv ) { _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); Player *pPlayer = player_new(); player_set_decoder( pPlayer, init_decoder() ); player_set_display( pPlayer, init_display() ); SDL_CreateThread( player_play, pPlayer ); player_run( pPlayer ); _CrtDumpMemoryLeaks(); getchar(); return 0; }
/** * @brief Function to active the new game menu. * @param str Unused. */ static void menu_main_new( unsigned int wid, char* str ) { (void) str; (void) wid; /* Closes the main menu window. */ window_destroy( wid ); menu_Close(MENU_MAIN); pause_game(); /* Start the new player. */ player_new(); }
void xml_team_read_start_element (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, GError **error) { #ifdef DEBUG printf("xml_team_read_start_element\n"); #endif if(strcmp(element_name, TAG_TEAM) == 0) state = STATE_TEAM; else if(strcmp(element_name, TAG_TEAM_NAME) == 0) state = STATE_TEAM_NAME; else if(strcmp(element_name, TAG_STADIUM_NAME) == 0) state = STATE_STADIUM_NAME; else if(strcmp(element_name, TAG_SYMBOL) == 0) state = STATE_SYMBOL; else if(strcmp(element_name, TAG_AVERAGE_TALENT) == 0) state = STATE_AVERAGE_TALENT; else if(strcmp(element_name, TAG_FORMATION) == 0) state = STATE_FORMATION; else if(strcmp(element_name, TAG_NAMES_FILE) == 0) state = STATE_NAMES_FILE; else if(strcmp(element_name, TAG_PLAYER) == 0) { state = STATE_PLAYER; new_player = player_new(team, ((gfloat)team->average_talent / 10000) * const_float("float_player_max_skill"), TRUE); } else if(strcmp(element_name, TAG_PLAYER_NAME) == 0) state = STATE_PLAYER_NAME; else if(strcmp(element_name, TAG_PLAYER_BIRTH_YEAR) == 0) state = STATE_PLAYER_BIRTH_YEAR; else if(strcmp(element_name, TAG_PLAYER_BIRTH_MONTH) == 0) state = STATE_PLAYER_BIRTH_MONTH; else if(strcmp(element_name, TAG_PLAYER_SKILL) == 0) state = STATE_PLAYER_SKILL; else if(strcmp(element_name, TAG_PLAYER_TALENT) == 0) state = STATE_PLAYER_TALENT; else if(strcmp(element_name, TAG_PLAYER_POSITION) == 0) state = STATE_PLAYER_POSITION; else debug_print_message("xml_team_read_start_element: unknown tag: %s; I'm in state %d\n", element_name, state); }
int com_players_rewrite(int p, param_list param) { int pT; int c; time_t t = time(0); DIR *dirp; char dname[MAX_FILENAME_SIZE]; struct dirent *dp; d_printf("BICS: Rewriting players data at %s\n", strltime(&t)); for (c = 'a'; c <= 'z'; c++) { sprintf(dname, "%s/%c", PLAYER_DIR, c); dirp = opendir(dname); if (!dirp) continue; for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { if (dp->d_name[0] == '.') continue; pprintf(p, "%s\n", dp->d_name); { pT = player_new(); if (player_read(pT, dp->d_name) == 0) { //player_save_DB(pT); pprintf(p,"BICS: Player %s saved.\n", player_globals.parray[pT].login); } else { pprintf(p,"BICS: Problem reading player %s.\n", dp->d_name); } player_remove(pT); } } closedir(dirp); } return COM_OK; }
static void Add__to__queue(void **queue, void **player){ struct command com; queue_t * q = queue_new(); player_t * pl[1]; pl[0] = player_new('w', 's', 'd', 'a', 'f'); char index = 'w'; char * moves; moves = player_get_moves(pl[0]); for (int i = 0; i < 5; i++){ if (moves[i] == index) { i++; com.command = i; com.players = pl[i]; assert_int_equal(queue_add(q, com),KK); } } queue_remove(&q); player_remove(&pl); }
static void Player__command__ErrorCommand(void **queue, void **player){ struct command com; queue_t * q = queue_new(); player_t * pl[1]; pl[0] = player_new('w', 's', 'd', 'a', 'f'); char index = 'y'; char * moves; moves = player_get_moves(pl[0]); for (int i = 0; i < 5; i++){ if (moves[i] == index) { i++; com.command = i; com.players = pl[i]; queue_add(q, com); //assert_int_equal(i,); } } assert_int_equal(queue_size(q),0); queue_remove(&q); player_remove(&pl); }
static void Double__queue(void **queue, void **player){ struct command com; queue_t * q = queue_new(); player_t * pl[1]; pl[0] = player_new('w', 's', 'd', 'a', 'f'); char index = 'w'; char * moves; moves = player_get_moves(pl[0]); for (int a = 0; a < 200; a++){ for (int i = 0; i < 5; i++){ if (moves[i] == index) { i++; com.command = i; com.players = pl[i]; queue_add(q, com); } } } assert_int_equal(queue_size(q),200); queue_remove(&q); player_remove(&pl); }
/* * remplayer * * Usage: remplayer name * * Removes an account. A copy of its files are saved under .rem.* which can * be found in the appropriate directory (useful in case of an accident). * * The account's details, messages, games and logons are all saved as * 'zombie' files. These zombie accounts are not listed in handles or * totals. */ int com_remplayer(int p, param_list param) { char *player = param[0].val.word; char playerlower[MAX_LOGIN_NAME]; int p1, lookup; strcpy(playerlower, player); stolower(playerlower); p1 = player_new(); lookup = player_read(p1, playerlower); if (!lookup) { if (!check_admin2(p, p1)) { pprintf(p, "You can't remove an admin with a level higher than or equal to yourself.\n"); player_remove(p1); return COM_OK; } } player_remove(p1); if (lookup) { pprintf(p, "No player by the name %s is registered.\n", player); return COM_OK; } if (player_find_bylogin(playerlower) >= 0) { pprintf(p, "A player by that name is logged in.\n"); return COM_OK; } if (!player_kill(playerlower)) { pprintf(p, "Player %s removed.\n", player); //UpdateRank(TYPE_CRAZYHOUSE, NULL, NULL, player); //UpdateRank(TYPE_STAND, NULL, NULL, player); //UpdateRank(TYPE_WILD, NULL, NULL, player); } else { pprintf(p, "Remplayer failed.\n"); } return COM_OK; }
static sexp sexp_player_new_stub (sexp ctx, sexp self, sexp_sint_t n) { struct player* *tmp; sexp res; res = sexp_make_cpointer(ctx, sexp_unbox_fixnum(sexp_opcode_return_type(self)), player_new(), SEXP_FALSE, 0); return res; }
static void application_instance_init (Application* self) { play = player_new(); }
/* * raisedead * * Usage: raisedead oldname [newname] * * Restores an account that has been previously removed using "remplayer". * The zombie files from which it came are removed. Under most * circumstances, you restore the account to the same handle it had * before (oldname). However, in some circumstances you may need to * restore the account to a different handle, in which case you include * "newname" as the new handle. After "raisedead", you may need to use the * "asetpasswd" command to get the player started again as a registered * user, especially if the account had been locked * by setting the password to *. */ int com_raisedead(int p, param_list param) { char *player = param[0].val.word; char *newplayer = (param[1].type == TYPE_NULL ? player : param[1].val.word); char playerlower[MAX_LOGIN_NAME], newplayerlower[MAX_LOGIN_NAME]; char plrFile[MAX_FILENAME_SIZE]; int p2, lookup; strcpy(playerlower, player); stolower(playerlower); strcpy(newplayerlower, newplayer); stolower(newplayerlower); /* First make sure we have a player to raise. */ sprintf (plrFile, "%s/%c/.rem.%s", PLAYER_DIR, playerlower[0], playerlower); if (!file_exists (plrFile)) { pprintf(p, "No deleted player %s.\n", player); return COM_OK; } /* Now check for registered player. */ sprintf (plrFile, "%s/%c/%s", PLAYER_DIR, newplayerlower[0], newplayerlower); if (file_exists (plrFile)) { pprintf(p, "A player named %s is already registered.\n", newplayerlower); pprintf(p, "Obtain a new handle for the dead person.\n"); pprintf(p, "Then use raisedead [oldname] [newname].\n"); return COM_OK; } /* Don't raise over a logged in user. */ if (player_find_bylogin(newplayerlower) >= 0) { pprintf(p, "A player named %s is logged in.\n", newplayerlower); pprintf(p, "Can't raise until that person leaves.\n"); return COM_OK; } /* OK, ready to go. */ if (!player_reincarn(playerlower, newplayerlower)) { if (param[1].type == TYPE_WORD) pprintf(p, "Player %s reincarnated to %s.\n", player, newplayer); else pprintf(p, "Player %s raised.\n", player); p2 = player_new(); if (!(lookup = player_read(p2, newplayerlower))) { if (param[1].type == TYPE_WORD) { free(player_globals.parray[p2].name); player_globals.parray[p2].name = strdup(newplayer); player_save(p2); } /*if (player_globals.parray[p2].s_stats.rating > 0) UpdateRank(TYPE_STAND, newplayer, &player_globals.parray[p2].s_stats, newplayer); if (player_globals.parray[p2].z_stats.rating > 0) UpdateRank(TYPE_CRAZYHOUSE, newplayer, &player_globals.parray[p2].z_stats, newplayer); if (player_globals.parray[p2].w_stats.rating > 0) UpdateRank(TYPE_WILD, newplayer, &player_globals.parray[p2].w_stats, newplayer);*/ } player_remove(p2); } else { pprintf(p, "Raisedead failed.\n"); } return COM_OK; #if 0 if (param[1].type == TYPE_NULL) { if (!player_raise(playerlower)) { pprintf(p, "Player %s raised from dead.\n", player); p1 = player_new(); if (!(lookup = player_read(p1, playerlower))) { /*if (player_globals.parray[p1].s_stats.rating > 0) UpdateRank(TYPE_STAND, player, &player_globals.parray[p1].s_stats, player); if (player_globals.parray[p1].z_stats.rating > 0) UpdateRank(TYPE_CRAZYHOUSE, player, &player_globals.parray[p1].z_stats, player); if (player_globals.parray[p1].w_stats.rating > 0) UpdateRank(TYPE_WILD, player, &player_globals.parray[p1].w_stats, player);*/ } player_remove(p1); } else { pprintf(p, "Raisedead failed.\n"); } return COM_OK; } else { if (player_find_bylogin(newplayerlower) >= 0) { pprintf(p, "A player by the requested name is logged in.\n"); pprintf(p, "Can't reincarnate until they leave.\n"); return COM_OK; } p2 = player_new(); lookup = player_read(p2, newplayerlower); player_remove(p2); if (!lookup) { pprintf(p, "A player by the name %s is already registered.\n", player); pprintf(p, "Obtain another new handle for the dead person.\n"); return COM_OK; } if (!player_reincarn(playerlower, newplayerlower)) { pprintf(p, "Player %s reincarnated to %s.\n", player, newplayer); p2 = player_new(); if (!(lookup = player_read(p2, newplayerlower))) { free(player_globals.parray[p2].name); player_globals.parray[p2].name = strdup(newplayer); player_save(p2); /*if (player_globals.parray[p2].s_stats.rating > 0) UpdateRank(TYPE_STAND, newplayer, &player_globals.parray[p2].s_stats, newplayer); if (player_globals.parray[p2].z_stats.rating > 0) UpdateRank(TYPE_CRAZYHOUSE, newplayer, &player_globals.parray[p2].z_stats, newplayer); if (player_globals.parray[p2].w_stats.rating > 0) UpdateRank(TYPE_WILD, newplayer, &player_globals.parray[p2].w_stats, newplayer);*/ } player_remove(p2); } else { pprintf(p, "Raisedead failed.\n"); } } return COM_OK; #endif }
/*ARGSUSED*/ void player_accept(void *unused) { static int conn_cnt; struct sockaddr *sap; struct player *np; socklen_t len; const char *p; int ns; int set = 1; int stacksize; char buf[128]; #ifdef RESOLVE_IPADDRESS struct hostent *hostp; #endif /* auto sockaddr_storage would be simpler, but less portable */ sap = malloc(player_addrlen); len = player_addrlen; if (getsockname(player_socket, sap, &len)) { logerror("getsockname() failed: %s", strerror(errno)); p = NULL; } else { p = sockaddr_ntop(sap, buf, sizeof(buf)); CANT_HAPPEN(!p); } logerror("Listening on %s", p ? buf : "unknown address"); while (1) { empth_select(player_socket, EMPTH_FD_READ, NULL); len = player_addrlen; ns = accept(player_socket, sap, &len); /* FIXME accept() can block on some systems (RST after select() reports ready) */ if (ns < 0) { logerror("new socket accept"); continue; } (void)setsockopt(ns, SOL_SOCKET, SO_KEEPALIVE, &set, sizeof(set)); np = player_new(ns); if (!np) { logerror("can't create player for fd %d", ns); close(ns); continue; } if (!sockaddr_ntop(sap, np->hostaddr, sizeof(np->hostaddr))) { CANT_REACH(); player_delete(np); continue; } logerror("Connect from %s", np->hostaddr); #ifdef RESOLVE_IPADDRESS hostp = gethostbyaddr(inaddr, player_addrlen, sap->sa_family); if (NULL != hostp) strcpy(np->hostname, hostp->h_name); #endif /* RESOLVE_IPADDRESS */ /* FIXME ancient black magic; figure out true stack need */ stacksize = 100000 /* budget */ + MAX(WORLD_SZ() * sizeof(int) * 7, /* power */ MAXNOC * sizeof(struct powstr)); sprintf(buf, "Conn%d", conn_cnt++); empth_create(player_login, stacksize, 0, buf, np); } }
void main_loop(ALLEGRO_EVENT_QUEUE *event_queue) { int color = 0, c2 = 0, c3 = 0; bool stlacene_tlacitka[ALLEGRO_KEY_MAX]; memset(stlacene_tlacitka, 0, sizeof(stlacene_tlacitka)); struct Player *player; player = player_new(); struct Objekt * obj = malloc(sizeof(struct Objekt)); list_add(&scena, obj); obj->objekt = player; obj->draw = player_draw; obj->destroy = player_destroy; obj->copy = player_copy; mutex = al_create_mutex(); ALLEGRO_THREAD *thread = al_create_thread(kresliace_vlakno, event_queue); al_start_thread(thread); for (;;) { ALLEGRO_EVENT event; al_wait_for_event(event_queue, &event); if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } if (event.type == ALLEGRO_EVENT_TIMER) { al_lock_mutex(mutex); if (stlacene_tlacitka[ALLEGRO_KEY_LEFT]) { player->x = player->x - 10; if (player->x < 0) player->x = 0; } if (stlacene_tlacitka[ALLEGRO_KEY_RIGHT]) { player->x = player->x + 10; if (player->x > SCREEN_W - 64) player->x = SCREEN_W - 64; } al_unlock_mutex(mutex); } if (event.type == ALLEGRO_EVENT_KEY_DOWN ||event.type == ALLEGRO_EVENT_KEY_UP) { ALLEGRO_KEYBOARD_STATE stav_klavesnice; al_get_keyboard_state(&stav_klavesnice); if (al_key_down(&stav_klavesnice, ALLEGRO_KEY_ESCAPE)) { break; } if (al_key_down(&stav_klavesnice, ALLEGRO_KEY_LEFT)) { stlacene_tlacitka[ALLEGRO_KEY_LEFT] = true; } else { stlacene_tlacitka[ALLEGRO_KEY_LEFT] = false; } if (al_key_down(&stav_klavesnice, ALLEGRO_KEY_RIGHT)) { stlacene_tlacitka[ALLEGRO_KEY_RIGHT] = true; } else { stlacene_tlacitka[ALLEGRO_KEY_RIGHT] = false; } if (al_key_down(&stav_klavesnice, ALLEGRO_KEY_UP)) { stlacene_tlacitka[ALLEGRO_KEY_UP] = true; } else { stlacene_tlacitka[ALLEGRO_KEY_UP] = false; } if (al_key_down(&stav_klavesnice, ALLEGRO_KEY_DOWN)) { stlacene_tlacitka[ALLEGRO_KEY_DOWN] = true; } else { stlacene_tlacitka[ALLEGRO_KEY_DOWN] = false; } } } al_destroy_thread(thread); }
/* * addplayer * * Usage: addplayer playername emailaddress realname * * Adds a local player to the server with the handle of "playername". For * example: * * addplayer Hawk [email protected] Henrik Gram */ int com_addplayer(int p, param_list param) { char text[2048]; char *newplayer = param[0].val.word; char *newname = param[2].val.string; char *newemail = param[1].val.word; char password[PASSLEN + 1]; char newplayerlower[MAX_LOGIN_NAME]; char salt[3]; int p1, lookup; int i; if (strlen (newplayer) >= MAX_LOGIN_NAME) { pprintf (p, "Player name is too long\n"); return COM_OK; } if (strlen (newplayer) < 3) { pprintf(p, "Player name is too short\n"); return COM_OK; } if (!alphastring (newplayer)) { pprintf (p, "Illegal characters in player name. Only A-Za-z allowed.\n"); return COM_OK; } strcpy (newplayerlower, newplayer); stolower (newplayerlower); p1 = player_new (); lookup = player_read (p1, newplayerlower); if (!lookup) { pprintf (p, "A player by the name %s is already registered.\n", newplayerlower); player_remove (p1); return COM_OK; } player_globals.parray[p1].name = strdup (newplayer); player_globals.parray[p1].login = strdup (newplayerlower); player_globals.parray[p1].fullName = strdup (newname); player_globals.parray[p1].emailAddress = strdup (newemail); for (i = 0; i < PASSLEN; i++) { password[i] = 'a' + random() % 26; } password[i] = '\0'; salt[0] = 'a' + random() % 26; salt[1] = 'a' + random() % 26; salt[2] = '\0'; player_globals.parray[p1].passwd = strdup (chessd_crypt (password, salt)); PFlagON (p1, PFLAG_REG); PFlagON (p1, PFLAG_RATED); player_add_comment (p, p1, "Player added by addplayer."); player_globals.parray[p1].timeOfReg = (int) time (0); player_save (p1); player_remove (p1); if ( (p1 = player_find_part_login(newplayer)) >= 0) { sprintf (text, "\nYour player account has been created.\n\n" "Login Name: %s\nFull Name: %s\nEmail Address: %s\nInitial Password: %s\n\n" "If any of this information is incorrect, please contact the administrator\n" "to get it corrected.\n\n" "You may change your password with the password command on the the server.\n" "\nPlease be advised that if this is an unauthorized duplicate account for\n" "you, by using it you take the risk of being banned from accessing this\n" "chess server.\n\n" "Regards,\n\nThe BICS admins\n", newplayer, newname, newemail, password); pprintf_prompt (p1, "%s", text); player_read (p1, newplayer); player_globals.parray[p1].timeOfReg = player_globals.parray[p1].logon_time; } pprintf (p, "Added: >%s< >%s< >%s< \n", newplayer, newname, newemail); pprintf (p, "Password %s\n", password); return COM_OK; }