Exemple #1
0
	void Client::Print( const char *msg ) const {
		ByteBuffer msgBuffer;
		if ( msgBuffer.WriteString( msg ) == ByteBuffer::Error::Success ) {
			Network::XSPacket msgPacket( Network::ID_XS_SV2CL_PRINT );
			msgPacket.data = msgBuffer.GetMemory( &msgPacket.dataLen );
			connection.Send( msgPacket );
		}
	}
Exemple #2
0
		//FIXME: selectively network to out-of-date clients (i.e. second client connecting later, not having the list
		//	of resources yet, but `modified` being false.
		//	`force` bool is a hack, perhaps drive the networking further up the chain according to client's GUIDs
		void NetworkResources( bool force ) {
			if ( modified || force ) {
				// send resource list
				ByteBuffer resourceBuffer;
				ServerGame::SerialiseResources( &resourceBuffer );

				Network::XSPacket resourcePacket( Network::ID_XS_SV2CL_RESOURCES );
				resourcePacket.data = resourceBuffer.GetMemory( &resourcePacket.dataLen );

				for ( auto &client : Server::clients ) {
					if ( !client.second ) {
						SDL_assert( !"Invalid client instance - did you instantiate and use before initialising?" );
						continue;
					}
					client.second->connection.Send( &resourcePacket );
				}

				modified = false;
			}
		}
Exemple #3
0
	bool Connection::ChangeState( Connection::State newState, bool doNetwork ) {
		if ( state == newState ) {
			// nothing to do
			return false;
		}

		const GraphContainer::const_iterator &it = connectionTransitionGraph.find( privateState );
		const StateList &node = it->second;
		if ( node.empty() || std::find( node.begin(), node.end(), newState ) == node.end() ) {
			console.Print( PrintLevel::Developer,
				"connection %" PRIX64 " state change failed: %s -> %s not allowed\n",
				guid,
				Connection::StateToString( state ),
				Connection::StateToString( newState )
			);
			return false;
		}

		console.Print( PrintLevel::Developer,
			"connection %" PRIX64 " state change (%s -> %s)\n",
			guid,
			Connection::StateToString( privateState ),
			Connection::StateToString( newState )
		);

		if ( doNetwork ) {
			ByteBuffer stateBuffer;
			if ( stateBuffer.Write<State>( newState ) != ByteBuffer::Error::Success ) {
				// ...
			}

			XSPacket statePacket( isServer ? ID_XS_SV2CL_CONNECTION_STATE : ID_XS_CL2SV_CONNECTION_STATE );
			statePacket.data = stateBuffer.GetMemory( &statePacket.dataLen );
			statePacket.Send( guid );
		}

		privateState = newState;
		return true;
	}