Example #1
0
/***********************************************************************
 * called when initiated connection process yields a result
 ***********************************************************************/
void GameClient::ZCom_cbConnectResult( ZCom_ConnID _id, eZCom_ConnectResult _result, ZCom_BitStream &_reply )
{
	m_zoi_id = _id;
	m_id = _reply.getInt(32);
	std::string reason(_reply.getStringStatic());

	std::stringstream strs;
	strs<<"Game Client: The connection process for: "<<m_zoi_id<<" returned with resultcode "<<_result<<", the reply was "<<reason;
	LogHandler::getInstance()->LogToFile(strs.str(), 2);   

	if ( _result != eZCom_ConnAccepted )
	{
		m_connected = false;
		if(reason == "")
			reason = "Server not reachable";

		InternalWorkpile::getInstance()->AddEvent(new GameErrorMessageEvent("Problem connecting to game server " + m_servername + " - " + reason));
	}
	else
	{
		m_connected = true;
		ZCom_requestDownstreamLimit(m_zoi_id, m_downpacketpersecond, m_downbyteperpacket);

		#ifndef _ZOID_USED_NEW_VERSION_
		ZCom_requestZoidMode( m_zoi_id, 1 );
		#else
		ZCom_changeObjectChannelSubscription( m_zoi_id, 1, eZCom_Subscribe );
		#endif
	}
}
Example #2
0
/***********************************************************************
 * connection has closed
 ***********************************************************************/
void GameClient::ZCom_cbConnectionClosed( ZCom_ConnID _id, eZCom_CloseReason _reason, 
									 ZCom_BitStream &_reasondata )
{
	std::stringstream strs;
	strs<<"Game Client: Connection with ID: "<<_id<<" has been closed, reason is: "<<_reasondata.getStringStatic();
	LogHandler::getInstance()->LogToFile(strs.str(), 2);   

	m_connected = false;

	//disconnect and get to login screen
	if(!m_disconnecting)
		InternalWorkpile::getInstance()->AddEvent(new DisplayGUIEvent(0));
}
Example #3
0
void Client::ZCom_cbDataReceived( ZCom_ConnID id, ZCom_BitStream& data) 
{
	int event = Encoding::decode(data, Network::ClientEvents::Max);
	switch(event)
	{
		case Network::ClientEvents::LuaEvents:
		{
			for(int t = Network::LuaEventGroup::Game;
				t < Network::LuaEventGroup::Max; ++t)
			{
				int c = data.getInt(8);
				for(int i = 0; i < c; ++i)
				{
					char const* name = data.getStringStatic();
					network.indexLuaEvent((Network::LuaEventGroup::type)t, name);
				}
			}
		}
		break;
	}
}
Example #4
0
/***********************************************************************
 * called when initiated connection process yields a result
 ***********************************************************************/
void MainServerClient::ZCom_cbConnectResult( ZCom_ConnID _id, eZCom_ConnectResult _result, ZCom_BitStream &_reply )
{
	m_zoi_id = _id;
	m_id = _reply.getInt(32);
	std::string reason(_reply.getStringStatic());

	if ( _result != eZCom_ConnAccepted )
	{
		m_connected = false;
	}
	else
	{
		m_connected = true;
		ZCom_requestDownstreamLimit(m_zoi_id, m_downpacketpersecond, m_downbyteperpacket);

		#ifndef _ZOID_USED_NEW_VERSION_
		ZCom_requestZoidMode( m_zoi_id, 1 );
		#else
		ZCom_changeObjectChannelSubscription( m_zoi_id, 1, eZCom_Subscribe );
		#endif
	}
}
Example #5
0
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;
                };*/
              };
            };
      };
    }
};
Example #6
0
void Client::ZCom_cbConnectResult( ZCom_ConnID _id, eZCom_ConnectResult _result, ZCom_BitStream &_reply )
{
	if ( _result != eZCom_ConnAccepted )
	{
		Network::ConnectionReply::type r = static_cast<Network::ConnectionReply::type>(_reply.getInt(8));
		if(r == Network::ConnectionReply::Retry)
		{
			DLOG("Got retry from server");
			network.reconnect(50);
		}
		else if(r == Network::ConnectionReply::Banned)
		{
			console.addLogMsg("* YOU ARE BANNED FROM THIS SERVER");
		}
		else
		{
			console.addLogMsg("* COULDNT ESTABLISH CONNECTION");
		}
	}
	else
	{
		network.setClient(true);
		ZCom_requestDownstreamLimit(_id, network.downPPS, network.downBPP);
		console.addLogMsg("* CONNECTION ACCEPTED");
		network.setServerID(_id);
		network.incConnCount();
		
		std::string mod = _reply.getStringStatic();
		std::string map = _reply.getStringStatic();
		game.refreshLevels();
		game.refreshMods();
		bool hasLevel = game.hasLevel(map);
		bool hasMod = game.hasMod(mod);
		
		if(!hasMod)
		{
			game.error(Game::ErrorModNotFound);
			//This doesn't work somewhy: network.disconnect();
			//And maybe we don't want to do it since it would overwrite our error message
		}
		else if(!hasLevel)
		{
			if(network.autoDownloads)
			{
				ZCom_requestZoidMode(_id, 2); // We need to update
				if(!hasLevel)
					updater.requestLevel(map);
			}
			else
				game.error(Game::ErrorMapNotFound);
		}
		else
		{
			game.setMod( mod );
			if(game.changeLevel( map, false ) && game.isLoaded())
			{
				game.runInitScripts();
				sendConsistencyInfo();
				ZCom_requestZoidMode(_id, 1);
			}
			else
			{
				console.addLogMsg("* COULDN'T LOAD MOD OR LEVEL");
				network.disconnect();
			}
		}
	}
}
Example #7
0
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;
	}
}