void worm::checkevents() { while (node->checkEventWaiting()) { ZCom_Node::eEvent type; // event type eZCom_NodeRole remote_role; // role of remote sender ZCom_ConnID conn_id; // connection id of sender int event; ZCom_BitStream *data = node->getNextEvent(&type, &remote_role, &conn_id); if (type == ZCom_Node::eEvent_AuthorityRemoved) { con->log.create_msg("PLAYER REMOVED"); deleteme = true; } else if (type == ZCom_Node::eEvent_User) { event=data->getInt(8); if(event==4) { strcpy(name,data->getStringStatic()); }else if(event==3) { char msg[1024],msg2[1024]; strcpy(msg,data->getStringStatic()); sprintf(msg2,"[%s] %s",name,msg); //strcat(msg2,msg); con->log.create_msg(msg2); con->echolist.add_echo(msg2); if (node->getRole()==eZCom_RoleAuthority) { sendmsg(msg); }; play_sample(game->menu_select->snd, *game->VOLUME, 127, 1300, 0); }else if(event==2) { int o; int _x=data->getInt(32); int _y=data->getInt(32); int _xspd=data->getInt(32); int _yspd=data->getInt(32); int _t=data->getInt(32); srand(_t); for (o=0;o<14;o++) partlist.shoot_part(rand()%1000*255,(rand()%200)+600,1,_x,_y-4000,_xspd/2,_yspd/2,this,game->gore); play_sample(game->death->snd, *game->VOLUME, 127, 1000, 0); deaths++; health=0; if (*game->RESPAWN_RELOAD==1) recharge_weapons(this); }else if(event==1) { int _x=data->getInt(32); int _y=data->getInt(32); int _xspd=data->getInt(32); int _yspd=data->getInt(32); int _ang=data->getInt(32); int _dir=data->getSignedInt(8); int _weap=data->getInt(16); int _t=data->getInt(32); srand(_t); fireing=true; weap[curr_weap].ammo--; if (weaps->num[_weap]->shoot_num!=0) { int dist,spd_rnd,xof,yof,h; for (h=0;h<weaps->num[_weap]->shoot_num;h++) { dist=((rand()%1000)*weaps->num[_weap]->distribution)-weaps->num[_weap]->distribution/2*1000; if (weaps->num[_weap]->shoot_spd_rnd!=0) spd_rnd=(rand()%weaps->num[_weap]->shoot_spd_rnd)-weaps->num[_weap]->shoot_spd_rnd/2; else spd_rnd=0; xof=fixtof(fixsin(ftofix((_ang-dist)/1000.)))*(int)(weaps->num[_weap]->shoot_obj->detect_range+1000)*_dir; yof=fixtof(fixcos(ftofix((_ang-dist)/1000.)))*(int)(weaps->num[_weap]->shoot_obj->detect_range+1000); partlist.shoot_part(_ang-dist,weaps->num[_weap]->shoot_spd-spd_rnd,_dir,_x+xof,_y-4000+yof,_xspd*(weaps->num[_weap]->affected_motion/1000.),_yspd*(weaps->num[_weap]->affected_motion/1000.),this,weaps->num[_weap]->shoot_obj); }; if (weaps->num[_weap]->aim_recoil!=0) aim_recoil_speed+=(100*weaps->num[_weap]->aim_recoil);/*-weap[curr_weap].weap->aim_recoil/2*1000;*/ if (weaps->num[_weap]->recoil!=0) { xspd = xspd + -fixtof(fixsin(ftofix(_ang/1000.)))*weaps->num[_weap]->recoil*_dir; yspd = yspd + -fixtof(fixcos(ftofix(_ang/1000.)))*weaps->num[_weap]->recoil; }; }; weap[curr_weap].shoot_time=0; firecone_time=weaps->num[_weap]->firecone_timeout; curr_firecone=weaps->num[_weap]->firecone; if (weaps->num[_weap]->shoot_sound!=NULL) { //if (weap->loop_sound!=1) play_sample(weaps->num[_weap]->shoot_sound->snd, *game->VOLUME, 127, 1000, 0); /*else if (!sound_loop) { play_sample(weap->shoot_sound->snd, 255, 127, 1000, 1); sound_loop=true; };*/ }; }; }; } };
void Server::ZCom_cbDataReceived( ZCom_ConnID _id, ZCom_BitStream &_data) { Network::NetEvents event = (Network::NetEvents) _data.getInt(8); switch( event ) { case Network::PLAYER_REQUEST: { std::string name = _data.getStringStatic(); int colour = _data.getInt(24); int team = _data.getSignedInt(8); unsigned int uniqueID = static_cast<unsigned int>(_data.getInt(32)); BaseWorm* worm = game.addWorm(true); if ( NetWorm* netWorm = dynamic_cast<NetWorm*>(worm) ) { netWorm->setOwnerId(_id); } BasePlayer* player = game.addPlayer ( Game::PROXY ); let_(i, savedScores.find(uniqueID)); if(i != savedScores.end()) { player->stats = i->second; player->getOptions()->uniqueID = uniqueID; } else { do { uniqueID = rndgen(); } while(!uniqueID); player->getOptions()->uniqueID = uniqueID; savedScores[uniqueID] = player->stats; } player->colour = colour; player->team = team; player->localChangeName( name ); console.addLogMsg( "* " + player->m_name + " HAS JOINED THE GAME"); player->assignNetworkRole(true); player->setOwnerId(_id); player->assignWorm(worm); } break; case Network::RConMsg: { char const* passwordSent = _data.getStringStatic(); if ( !game.options.rConPassword.empty() && game.options.rConPassword == passwordSent ) { //console.addQueueCommand(_data.getStringStatic()); console.parseLine(_data.getStringStatic()); } } break; case Network::ConsistencyInfo: { int clientProtocol = _data.getInt(32); if(clientProtocol != Network::protocolVersion) { network.disconnect(_id, Network::IncompatibleProtocol); } if(!game.checkCRCs(_data) && network.checkCRC) // We call checkCRC anyway so that the stream is advanced network.disconnect(_id, Network::IncompatibleData); } break; } }