Skip to main content
added 27 characters in body; edited title
Source Link
user1430
user1430

Lidgren client connection How can I create the correct player object based on a type in a network message?

I am using lidgren as a networking library for a small xnaXNA game. I am using a server client/server architecture for the game. Currently, I have the client and server connecting but I would like to be able to pass an enum with a character type when the client requests to join the server. Here is a sample of my code:

while ((inMsg = networkManager.ReadMessage()) != null)
        {

            switch (inMsg.MessageType){
                case NetIncomingMessageType.StatusChanged:
                    switch ((NetConnectionStatus)inMsg.ReadByte()){
                        case NetConnectionStatus.Connected:
                            if (!this.isHosting)
                            {
                              //Extract player info from message and create a local player                             
                            }break;
                        case NetConnectionStatus.RespondedAwaitingApproval:
                            pType = (PlayerType)inMsg.ReadByte();
                            playerManager.AddPlayer(pType);
                            //Then I will send the player information to the client
                            inMsg.SenderConnection.Approve();
                            break;
                    }
                    break;

            }

            this.networkManager.Recycle(inMsg);
        }

So whenWhen server gets a message with RespondedAwaitingApprovalRespondedAwaitingApproval flag, iI would like to be able to read the message,extract extract the type and create an instance of a player of that type. How can I accomplish that?

Lidgren client connection player type

I am using lidgren as a networking library for a small xna game. I am using a server client architecture for the game. Currently, I have the client and server connecting but I would like to be able to pass an enum with a character type when the client requests to join the server. Here is a sample of my code

while ((inMsg = networkManager.ReadMessage()) != null)
        {

            switch (inMsg.MessageType){
                case NetIncomingMessageType.StatusChanged:
                    switch ((NetConnectionStatus)inMsg.ReadByte()){
                        case NetConnectionStatus.Connected:
                            if (!this.isHosting)
                            {
                              //Extract player info from message and create a local player                             
                            }break;
                        case NetConnectionStatus.RespondedAwaitingApproval:
                            pType = (PlayerType)inMsg.ReadByte();
                            playerManager.AddPlayer(pType);
                            //Then I will send the player information to the client
                            inMsg.SenderConnection.Approve();
                            break;
                    }
                    break;

            }

            this.networkManager.Recycle(inMsg);
        }

So when server gets a message with RespondedAwaitingApproval flag, i would like to be able to read the message,extract the type and create an instance of a player of that type.

How can I create the correct player object based on a type in a network message?

I am using lidgren as a networking library for a small XNA game. I am using a client/server architecture for the game. Currently, I have the client and server connecting but I would like to be able to pass an enum with a character type when the client requests to join the server. Here is a sample of my code:

while ((inMsg = networkManager.ReadMessage()) != null)
        {

            switch (inMsg.MessageType){
                case NetIncomingMessageType.StatusChanged:
                    switch ((NetConnectionStatus)inMsg.ReadByte()){
                        case NetConnectionStatus.Connected:
                            if (!this.isHosting)
                            {
                              //Extract player info from message and create a local player                             
                            }break;
                        case NetConnectionStatus.RespondedAwaitingApproval:
                            pType = (PlayerType)inMsg.ReadByte();
                            playerManager.AddPlayer(pType);
                            //Then I will send the player information to the client
                            inMsg.SenderConnection.Approve();
                            break;
                    }
                    break;

            }

            this.networkManager.Recycle(inMsg);
        }

When server gets a message with RespondedAwaitingApproval flag, I would like to be able to read the message, extract the type and create an instance of a player of that type. How can I accomplish that?

Source Link
John
  • 201
  • 2
  • 6

Lidgren client connection player type

I am using lidgren as a networking library for a small xna game. I am using a server client architecture for the game. Currently, I have the client and server connecting but I would like to be able to pass an enum with a character type when the client requests to join the server. Here is a sample of my code

while ((inMsg = networkManager.ReadMessage()) != null)
        {

            switch (inMsg.MessageType){
                case NetIncomingMessageType.StatusChanged:
                    switch ((NetConnectionStatus)inMsg.ReadByte()){
                        case NetConnectionStatus.Connected:
                            if (!this.isHosting)
                            {
                              //Extract player info from message and create a local player                             
                            }break;
                        case NetConnectionStatus.RespondedAwaitingApproval:
                            pType = (PlayerType)inMsg.ReadByte();
                            playerManager.AddPlayer(pType);
                            //Then I will send the player information to the client
                            inMsg.SenderConnection.Approve();
                            break;
                    }
                    break;

            }

            this.networkManager.Recycle(inMsg);
        }

So when server gets a message with RespondedAwaitingApproval flag, i would like to be able to read the message,extract the type and create an instance of a player of that type.