Ejemplo n.º 1
0
/***********************************************************
data received from the server
***********************************************************/
void GameClient::ZCom_cbDataReceived( ZCom_ConnID _id, ZCom_BitStream &_data )
{
	//check message type
	unsigned int type = _data.getInt(4);

	switch(type)
	{
		//player is in waiting queue
		case 0:
			//inform user through the gui
			InternalWorkpile::getInstance()->AddEvent(new GameErrorMessageEvent("Map server is full. You have been queued for connection. Please wait for a moment you will get connected automatically..."));
		break;

		//change zoidlevel
		case 1:
			unsigned int newlvl = _data.getInt(32);

			std::stringstream strs;
			strs<<"Game Client: Changing zoidlevel to: "<<newlvl;
			LogHandler::getInstance()->LogToFile(strs.str(), 2);   

			ZCom_requestZoidMode(newlvl, 1);
		break;


	}
}
Ejemplo n.º 2
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
	}
}
Ejemplo n.º 3
0
	bool NetWorld::recUserEvent(ZCom_Node *_node, ZCom_ConnID _from,
					eZCom_NodeRole _remoterole, ZCom_BitStream &_data,
					zU32 _estimated_time_sent)
	{
		unsigned int Id = _data.getInt(16);

		if(Id == Protocol::GameStartNotify::Id)
		{
			Protocol::GameStartNotify notify;
			notify.read(_data); // has to be called
			m_gamerunning = true;
		}
		else if(Id == Protocol::LevelSelect::Id)
		{
			Protocol::LevelSelect select;
			select.read(_data);

			SetLevel(select.name);

			// TODO: always accept the level

			Protocol::LevelConfirm confirm;
			ZCom_BitStream * stream = new ZCom_BitStream;
			confirm.write(*stream);
			this->sendEventDirect(eZCom_ReliableOrdered, stream, _from);
		}
		else if(Id == Protocol::SetCameraChase::Id)
		{
			Protocol::SetCameraChase chase;
 			chase.read(_data);
			if(m_camera)
				m_camera->SetCameraChase(chase.nodeid, chase.distance, chase.height, chase.follow_pitch);
		}
		else if(Id == Protocol::SetCameraPos::Id)
		{
			Protocol::SetCameraPos position;
 			position.read(_data);
			if(m_camera)
				m_camera->SetCameraPos(
					position.position_begin,
					position.position_end,
					position.lookat_begin,
					position.lookat_end,
					position.seconds
				);
		}
		return false;
	}
Ejemplo n.º 4
0
	bool NetObject::recUserEvent(ZCom_Node *_node, ZCom_ConnID _from,
					eZCom_NodeRole _remoterole, ZCom_BitStream &_data,
					zU32 _estimated_time_sent)
	{
		// Received event from remote node
		unsigned int Id = _data.getInt(16);

		if(Id == Protocol::NodeStateUpdate::Id)
		{
			Protocol::NodeStateUpdate state;
			state.read(_data);

			bool dirty = false;

			if(m_mesh != state.mesh)
			{
				dirty = true;
				m_mesh = state.mesh;
			}
			if(m_texture != state.texture)
			{
				dirty = true;
				m_texture = state.texture;
			}
			core::vector3df scale(
				state.mesh_scale.x(),
				state.mesh_scale.y(),
				state.mesh_scale.z()
			);
			if(m_meshScale.getDistanceFromSQ(scale)>0.0001) // TODO: compare with epsilon
			{
				dirty = true;
				m_meshScale = scale;
			}
//			std::cout << "Updated: " << m_texture << ", " << m_mesh << ", " << m_meshScale << std::endl;

			if(dirty)
				reloadNode();
		}
		else
		{
			std::cerr << "FATAL: Unhandled node message with id: " << Id << std::endl;
		}

		return false;
	}
Ejemplo n.º 5
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;
	}
}
Ejemplo n.º 6
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
	}
}
Ejemplo n.º 7
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;
                };*/
              };
            };
      };
    }
};
Ejemplo n.º 8
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();
			}
		}
	}
}
Ejemplo n.º 9
0
void Client::ZCom_cbConnectionClosed(ZCom_ConnID _id, eZCom_CloseReason _reason, ZCom_BitStream &_reasondata)
{
	network.decConnCount();
	switch( _reason )
	{
		case eZCom_ClosedDisconnect:
		{
			Network::DConnEvents dcEvent = static_cast<Network::DConnEvents>( _reasondata.getInt(8) );
			switch( dcEvent )
			{
				case Network::ServerMapChange:
				{
					console.addLogMsg("* SERVER CHANGED MAP");
					network.reconnect(150);
					game.reset(Game::ServerChangeMap);
				}
				break;
				case Network::Quit:
				{
					console.addLogMsg("* CONNECTION CLOSED BY SERVER");
					game.reset(Game::ServerQuit);
				}
				break;
				case Network::Kick:
				{
					console.addLogMsg("* YOU WERE KICKED");
					game.reset(Game::Kicked);
				}
				break;
				case Network::IncompatibleData:
				{
					console.addLogMsg("* YOU HAVE INCOMPATIBLE DATA");
					game.reset(Game::IncompatibleData);
				}
				break;
				
				case Network::IncompatibleProtocol:
				{
					console.addLogMsg("* THE HOST RUNS AN INCOMPATIBLE VERSION OF GUSANOS");
					game.reset(Game::IncompatibleProtocol);
				}
				break;
				
				default:
				{
					console.addLogMsg("* CONNECTION CLOSED BY DUNNO WHAT :O");
					game.reset(Game::ServerQuit);
				}
				break;
			}
		}
		break;
		
		case eZCom_ClosedTimeout:
			console.addLogMsg("* CONNECTION TIMEDOUT");
			game.reset(Game::ServerQuit);
		break;
		
		case eZCom_ClosedReconnect:
			console.addLogMsg("* CONNECTION RECONNECTED");
		break;
		
		default:
		break;
	}
	
	DLOG("A connection was closed");
}
Ejemplo n.º 10
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;
	}
}