RakNet - Problem with "Message Identifiers"

Hello guys, I am very new to RakNat and played around these days with the middleware.
I can say that I love it. It is very easy to use. But I got a problem with the message identifiers.
First of all I follwed their tutorials and the documentation and so on. I also hope that some guys of
you using this middleware. So I created my server like this:



#include <stdio.h>
#include <string.h>
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include "RakNetTypes.h"  // MessageID
#include "NetworkIDManager.h"
#include "NetworkIDObject.h"

#define MAX_CLIENTS 10
#define SERVER_PORT 60000

enum GameMessages
{	
	
	ID_GAME_MESSAGE_1 = ID_USER_PACKET_ENUM + 1,
	ID_LOGIN_MESSAGE = ID_USER_PACKET_ENUM + 2,
	 
	
};

//####################################################################################
//Hier beginnt eine Paketstruktur
#pragma pack(push, 1)
struct structName
{
	unsigned char useTimeStamp; // Assign ID_TIMESTAMP to this
	RakNet::Time timeStamp; // Put the system time in here returned by RakNet::GetTime()
	unsigned char typeId; // You should put here an enum you defined after the last one defined in MessageIdentifiers.h, lets say ID_SET_TIMED_MINE
	float x, y, z; // Mine position
	RakNet::NetworkID networkId; // NetworkID of the mine, used as a common method to refer to the mine on different computers
	RakNet::SystemAddress systemAddress; // The SystenAddress of the player that owns the mine
};
#pragma pack(pop)
//####################################################################################

//####################################################################################
//Hier beginnt eine Paketstruktur - LOGIN
#pragma pack(push, 1)
struct loginStruct
{
	unsigned char useTimeStamp; // Assign ID_TIMESTAMP to this
	RakNet::Time timeStamp; // Put the system time in here returned by RakNet::GetTime()
	unsigned char typeId; // You should put here an enum you defined after the last one defined in MessageIdentifiers.h, lets say ID_SET_TIMED_MINE
	RakNet::RakString username, password, securityToken;
	RakNet::NetworkID networkId; // NetworkID of the mine, used as a common method to refer to the mine on different computers
	RakNet::SystemAddress systemAddress; // The SystenAddress of the player that owns the mine


};
#pragma pack(pop)
//####################################################################################

int main(void)
{
	char str[512];

	RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
	bool isServer;
	RakNet::Packet *packet;

	printf("(C) or (S)erver?
");
	gets(str);

	if ((str[0] == 'c') || (str[0] == 'C'))
	{
		RakNet::SocketDescriptor sd;
		peer->Startup(1, &sd, 1);
		isServer = false;
	}
	else {
		RakNet::SocketDescriptor sd(SERVER_PORT, 0);
		peer->Startup(MAX_CLIENTS, &sd, 1);
		isServer = true;
	}

	if (isServer)
	{
		printf("Starting the server.
");
		// We need to let the server accept incoming connections from the clients
		peer->SetMaximumIncomingConnections(MAX_CLIENTS);
	}
	else {
		printf("Enter server IP or hit enter for 127.0.0.1
");
		gets(str);
		if (str[0] == 0){
			strcpy(str, "127.0.0.1");
		}
		printf("Starting the client.
");
		peer->Connect(str, SERVER_PORT, 0, 0);

	}

	while (1)
	{
		for (packet = peer->Receive(); packet; peer->DeallocatePacket(packet), packet = peer->Receive())
		{
			switch (packet->data[0])
			{
			case ID_REMOTE_DISCONNECTION_NOTIFICATION:
				printf("Another client has disconnected.
");
				break;
			case ID_REMOTE_CONNECTION_LOST:
				printf("Another client has lost the connection.
");
				break;
			case ID_REMOTE_NEW_INCOMING_CONNECTION:
				printf("Another client has connected.
");
				break;
			case ID_CONNECTION_REQUEST_ACCEPTED:
			{
				printf("Our connection request has been accepted.
");

				// Use a BitStream to write a custom user message
				// Bitstreams are easier to use than sending casted structures, and handle endian swapping automatically
				RakNet::BitStream bsOut;
				bsOut.Write((RakNet::MessageID)ID_GAME_MESSAGE_1);
				bsOut.Write("Das ist vom Client gesendet!!!");
				peer->Send(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, packet->systemAddress, false);
				
			}
				break;
			case ID_NEW_INCOMING_CONNECTION:
			{
				printf("A connection is incoming.
");
				RakNet::BitStream bsOut;
				bsOut.Write((RakNet::MessageID)ID_GAME_MESSAGE_1);
				bsOut.Write("Das ist vom Server gesendet!!!");
				peer->Send(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, packet->systemAddress, false);
				
			}
				break;
			case ID_NO_FREE_INCOMING_CONNECTIONS:
				printf("The server is full.
");
				break;
			case ID_DISCONNECTION_NOTIFICATION:
				if (isServer){
					printf("A client has disconnected.
");
				}
				else {
					printf("We have been disconnected.
");
				}
				break;
			case ID_CONNECTION_LOST:
				if (isServer){
					printf("A client lost the connection.
");
				}
				else {
					printf("Connection lost.
");
				}
				break;

			case ID_GAME_MESSAGE_1:
			{
				RakNet::RakString rs;
				RakNet::BitStream bsIn(packet->data, packet->length, false);
				bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
				bsIn.Read(rs);
				printf("%s
", rs.C_String());
				
			}
				break;

			case ID_LOGIN_MESSAGE:
			{
				RakNet::RakString rs;
				RakNet::BitStream bsIn(packet->data, packet->length, false);
				bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
				bsIn.Read(rs);
				printf("%s
", rs.C_String());
				

			}
				break;

			default:
				printf("Message with identifier %i has arrived.
", packet->data[0]);
				break;
			}
		}
	}


	RakNet::RakPeerInterface::DestroyInstance(peer);

	return 0;
}


So I have these cases:



enum GameMessages
{
	ID_GAME_MESSAGE_1 = ID_USER_PACKET_ENUM + 1,
	ID_LOGIN_MESSAGE = ID_USER_PACKET_ENUM + 2,
	
	
};


  • ID_GAME_MESSAGE_1 means number 135

  • ID_LOGIN_MESSAGE means number 136

like you can see inside the code above with exact the same content inside the cases:



case ID_GAME_MESSAGE_1:
			{
				RakNet::RakString rs;
				RakNet::BitStream bsIn(packet->data, packet->length, false);
				bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
				bsIn.Read(rs);
				printf("%s
", rs.C_String());
				
			}
				break;

			case ID_LOGIN_MESSAGE:
			{
				RakNet::RakString rs;
				RakNet::BitStream bsIn(packet->data, packet->length, false);
				bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
				bsIn.Read(rs);
				printf("%s
", rs.C_String());
				

			}
				break;


The same code inside the client application. Here is how I test to send a packet:


void ANetwork::sendLoginPacket(FString username, FString password){
	
	//ID_GAME_MESSAGE_1
	//ID_LOGIN_MESSAGE
		
		RakNet::BitStream bsOut;
		bsOut.Write((RakNet::MessageID)ID_GAME_MESSAGE_1);
		bsOut.Write("Message one is working");
		peer->Send(&bsOut, HIGH_PRIORITY, RELIABLE, 0, saddr, false);
	

}

I am able so send a packet. For example the “ID_GAME_MESSAGE_1” packet and the server is doing it the right way by printing the content to the console, in this case “Drank Stamina Pot”. All following packages which has another number like the “ID_LOGIN_PACKAGE” are recognized wrong so if I send the login package the console prints: “Message with identifier 136 has arrived” instead of doing the right case. I can send “ID_GAME_MESSAGE_1” over and over and it is working right. But the other one dont. Maybe you can help me…
Thank you for reading…

Greetings

Just close and/or delete this. I just forget to build… What a noob mistake:)