Esempio n. 1
0
void SMOnlineRoom::RelayChat(unsigned int clientNum, const MString &chat) {

    //First, Remove any unicode in the chat message and load it
    //into a temp message.

    MString sEndChat;

    sEndChat = Detranslit( chat );

    unsigned int numPlayers = m_clients[clientNum]->GetNumPlayers();

    m_reply.ClearPacket();

    //For all clients who support colored text:
    MString message = m_commonColor +
                      m_clients[clientNum]->GetColor();

    for (unsigned int x = 0; x < numPlayers; ++x) {
        message += m_clients[clientNum]->GetPlayerName(x);
        if ((numPlayers > 1) && (x < (numPlayers - 1)))
            message += "&";
    }

    message +=	":" + m_commonColor + m_baseColor + " ";
    message += sEndChat;

    m_reply.ClearPacket();
    m_reply.Write1(NSCCM + NSServerOffset);
    m_reply.WriteNT(message);
    SendToAllClients( m_reply, 2, 2 );


    //For all clients who do not support colored text:
    message = "";

    for (unsigned int x = 0; x < numPlayers; ++x) {
        message += m_clients[clientNum]->GetPlayerName(x);
        if ((numPlayers > 1) && (x < (numPlayers - 1)))
            message += "&";
    }

    message += ": " + sEndChat;// + MString( itoa( m_clients[clientNum]->GetVersion(), "  ",10 ));

    CHATLOG->QuietWrite(message);

    m_reply.ClearPacket();
    m_reply.Write1(NSCCM + NSServerOffset);
    m_reply.WriteNT(message);
    SendToAllClients( m_reply, 1, 1 );
}
void StepManiaLanServer::ServerChat(const CString& message)
{
	CString x = servername + ": " + message;
	Reply.ClearPacket();
	Reply.Write1(NSCCM + NSServerOffset);
	Reply.WriteNT(x);
	SendToAllClients(Reply);
}
Esempio n. 3
0
void NetworkManager::PlayerDied(int id)
{
	bufMutex.lock();

	head->id = id;
	head->cmd = PLAYER_DIED;
	SendToAllClients();

	bufMutex.unlock();
}
Esempio n. 4
0
void SMOnlineRoom::SendPlayersList() {
    unsigned int numplayers = m_PlayersList.size();

    m_reply.ClearPacket();
    m_reply.Write1(NSCUUL + NSServerOffset);
    m_reply.Write1(numplayers);
    m_reply.Write1(numplayers);

    for (unsigned int x = 0; x < numplayers; ++x) {
        m_reply.Write1(m_PlayersList[x]->ScreenPosition());
        m_reply.WriteNT(m_PlayersList[x]->GetName());
    }
    SendToAllClients(m_reply);
}
Esempio n. 5
0
void HandleRequest(int clientID, __CSERVE_Session session){
    char* buffer = calloc(1, 512);
    
    int IsLoggedIn = false;
    
    for(;;){
        char** request = SplitRequest(ReadLine(session.sock),'/');
        
        if(strncmp(request[0],MoveRequest, strlen(MoveRequest)) == 0 && IsLoggedIn){
                sprintf(buffer, "M/%d/%s/%s/\n", clientID, request[1], request[2], request[3]);
                SendToAllClients(buffer, strlen(buffer));
                memset(buffer, 0, 512);
        } else if(strncmp(request[0],LoginRequest, strlen(MoveRequest)) == 0){
                sprintf(buffer, "L/1\n");
                write(session.sock, buffer, strlen(buffer));
                memset(buffer, 0, 512);
                IsLoggedIn = true;
        } else if(strncmp(request[0],SayRequest, strlen(MoveRequest)) == 0 && IsLoggedIn){
                sprintf(buffer, "S/%d/%s/\n", clientID, request[1]);
                SendToAllClients(buffer, strlen(buffer));
                memset(buffer, 0, 512);
        }
    }
}
void StepManiaLanServer::SendUserList()
{
	Reply.ClearPacket();
	Reply.Write1(NSCUUL + NSServerOffset);
	Reply.Write1( (uint8_t) Client.size()*2 );
	Reply.Write1( (uint8_t) Client.size()*2 );

	for (unsigned int x = 0; x < Client.size(); ++x)
		for (int y = 0; y < 2; ++y)
		{
			if (Client[x]->Player[y].name.length() == 0)
				Reply.Write1(0);
			else
				Reply.Write1(1);
			Reply.WriteNT(Client[x]->Player[y].name);
		}

	SendToAllClients(Reply);
}
void StepManiaLanServer::RelayChat(CString &passedmessage, const unsigned int clientNum)
{
	Reply.ClearPacket();
	CString message = "";

	message += Client[clientNum]->Player[0].name;

	if (Client[clientNum]->twoPlayers)
			message += "&";

	message += Client[clientNum]->Player[1].name;

	message += ": ";
	message += passedmessage;
	Reply.Write1(NSCCM + NSServerOffset);
	Reply.WriteNT(message);

	SendToAllClients(Reply);
}
Esempio n. 8
0
//TODO: THERE IS A TODO IN HERE!!!
int NetworkManager::UpdateAllClients()
{
	bufMutex.lock();

	//std::cout << "Pushing to all clients" << std::endl;
	head->cmd = SERVER_UPDATE;
	//TODO: FILL THE BUFFER WITH THE ENTIRE OF EVERYTHING FOR ALL CLIENTS
	int bufferIndex = 0;

	game->physicsMutex.lock();

	float temp[MAX_SHIPS];
	memcpy(temp, game->GetShipPos()->x, sizeof(float) * MAX_SHIPS);

	//Ship Pos
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetShipPos()->x, sizeof(float) * MAX_SHIPS);
	bufferIndex += sizeof(float) * MAX_SHIPS;
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetShipPos()->y, sizeof(float) * MAX_SHIPS);
	bufferIndex += sizeof(float) * MAX_SHIPS;

	//Ship Rot
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetShipPos()->x, sizeof(float) * MAX_SHIPS);
	bufferIndex += sizeof(float) * MAX_SHIPS;
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetShipPos()->y, sizeof(float) * MAX_SHIPS);
	bufferIndex += sizeof(float) * MAX_SHIPS;

	//Ships Alive
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetShipsAlive(), sizeof(bool) * MAX_SHIPS);
	bufferIndex += sizeof(bool) * MAX_SHIPS;

	//Light Pos
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetLightPos()->x, sizeof(float) * MAX_LIGHTS);
	bufferIndex += sizeof(float) * MAX_LIGHTS;
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetLightPos()->y, sizeof(float) * MAX_LIGHTS);
	bufferIndex += sizeof(float) * MAX_LIGHTS;

	//Light Rot
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetLightPos()->x, sizeof(float) * MAX_LIGHTS);
	bufferIndex += sizeof(float) * MAX_LIGHTS;
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetLightPos()->y, sizeof(float) * MAX_LIGHTS);
	bufferIndex += sizeof(float) * MAX_LIGHTS;

	//Asteroid Pos
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetAsteroidPos()->x, sizeof(float) * MAX_ASTEROIDS);
	bufferIndex += sizeof(float) * MAX_ASTEROIDS;
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetAsteroidPos()->y, sizeof(float) * MAX_ASTEROIDS);
	bufferIndex += sizeof(float) * MAX_ASTEROIDS;

	//Asteroid Radius
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetAsteroidRadius()->value, sizeof(float) * MAX_ASTEROIDS);
	bufferIndex += sizeof(float) * MAX_ASTEROIDS;

	//Bullet Pos
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetBulletPos()->x, sizeof(float) * MAX_BULLETS);
	bufferIndex += sizeof(float) * MAX_BULLETS;
	memcpy(buf + sizeof(Header) + bufferIndex, game->GetBulletPos()->y, sizeof(float) * MAX_BULLETS);
	bufferIndex += sizeof(float) * MAX_BULLETS;

	SendToAllClients();

	game->physicsMutex.unlock();

	bufMutex.unlock();

	//std::cout << "Finished sending to all clients" << sizeof(Vec2) << std::endl;
	return EXIT_SUCCESS;
}
Esempio n. 9
0
void SMOnlineRoom::ChatAsServer(const MString& message) {
    WriteChatPacket(m_reply, SERVER->GetName() + ": " + Detranslit(message));
    SendToAllClients(m_reply);
}
Esempio n. 10
0
void SMOnlineRoom::SendRoomList() {
    WriteRoomListPacket(m_reply);
    SendToAllClients(m_reply);
}