bool server_game_start(char *game_script_name,int skill,network_reply_join_remotes *remotes,char *err_str) { int n; network_request_object_add *obj_add; // initialize lists model_initialize(); object_initialize_list(); weapon_initialize_list(); proj_setup_initialize_list(); scripts_initialize(); script_globals_initialize(); timers_initialize(); // setup skill level server.skill=skill; // run game script map.info.name[0]=0x0; map.info.player_start_name[0]=0x0; map.info.player_start_type[0]=0x0; map.info.in_load=FALSE; server.player_obj_uid=-1; js.game_attach.thing_type=thing_type_game; js.game_attach.thing_uid=-1; scripts_clear_attach_data(&js.game_attach); if (!scripts_add(&js.game_attach,"Game",game_script_name,NULL,err_str)) return(FALSE); // editor map override? if (setup.editor_override.on) { strcpy(map.info.name,setup.editor_override.map); } // can't start a game without a map if (map.info.name[0]==0x0) { strcpy(err_str,"Game: No start map specified in game script"); return(FALSE); } // prepare for any script based spawns object_script_spawn_start(); // put in additional objects (remotes, bots) if (remotes!=NULL) { obj_add=remotes->objects; for (n=0;n!=remotes->count;n++) { remote_add(obj_add,FALSE); obj_add++; } } // start player object server.player_obj_uid=object_start(NULL,TRUE,bt_game,-1,err_str); if (server.player_obj_uid==-1) { scripts_dispose(js.game_attach.script_uid); return(FALSE); } // force player to auto-spawn // spawing of player needs to happen before map_start events object_spawn(object_find_uid(server.player_obj_uid)); // finish any script based spawns object_script_spawn_finish(); return(TRUE); }
int net_host_join_request(net_address_type *addr,network_request_join *request_join) { int net_uid, tint_color_idx; char *c; obj_type *obj; network_reply_join reply_join; network_request_remote_add add; // check if join is OK net_uid=-1; reply_join.deny_reason[0]=0x0; // create remote UID when // adding this new remote player tint_color_idx=0; if (net_host_join_request_ok(request_join,&reply_join)) { tint_color_idx=htons((short)request_join->tint_color_idx); net_uid=net_host_player_add(addr,FALSE,request_join->name,request_join->draw_name,tint_color_idx); } // construct the reply reply_join.join_net_uid=htons((short)net_uid); reply_join.team_idx=htons((short)net_team_none); reply_join.map_tick=htonl(game_time_get()-map.start_game_tick); // build a remote add request for other // clients in the game // so we can add a remote, we start with a fake // team (none), after we add, we can call the game // rules and reset it add.add_net_uid=htons((short)net_uid); add.type=htons((short)object_type_remote_player); strncpy(add.name,request_join->name,name_str_len); strncpy(add.script_name,request_join->script_name,name_str_len); c=strrchr(add.script_name,'.'); // remove .js if (c!=0x0) *c=0x0; strncpy(add.draw_name,request_join->draw_name,name_str_len); add.team_idx=htons((short)net_team_none); add.tint_color_idx=htons((short)tint_color_idx); add.score=0; add.name[name_str_len-1]=0x0; add.script_name[name_str_len-1]=0x0; add.draw_name[name_str_len-1]=0x0; // create the remote object if (!remote_add(&add)) { net_uid=-1; } // run team rule if (net_uid!=-1) { obj=object_find_remote_net_uid(net_uid); object_multiplayer_setup(obj); // reset team in reply and remote add reply_join.team_idx=htons((short)obj->team_idx); add.team_idx=htons((short)obj->team_idx); } // send reply back to client if (!net_sendto_msg(host_socket,addr,net_action_reply_join,(unsigned char*)&reply_join,sizeof(network_reply_join))) { if (net_uid!=-1) net_host_player_remove_by_uid(net_uid); return(FALSE); } // if no player uid, then player was rejected if (net_uid==-1) return(FALSE); // send all other players on host the new player for remote add net_host_player_send_message_to_clients_all(addr,net_action_request_remote_add,(unsigned char*)&add,sizeof(network_request_remote_add)); return(net_uid); }