ReadVariableInt32() публичный Метод

Reads a variable sized Int32 written using WriteVariableInt32()
public ReadVariableInt32 ( ) : int
Результат int
Пример #1
0
        private static void HandleProtocol(NetIncomingMessage inc, byte packetheader, NetServer server)
        {
            switch ((PacketTypes.Headers) packetheader)
            {
                case PacketTypes.Headers.ReadyUpdate:
                    bool playerStatus = Convert.ToBoolean(inc.ReadString());
                    Player thePlayer = LookUpPlayer(inc.SenderConnection.RemoteUniqueIdentifier);

                    Console.WriteLine("Player {0} changed status to {1}", thePlayer.Name, playerStatus);
                    Players[inc.SenderConnection.RemoteUniqueIdentifier].ToggleReady();
                    NetOutgoingMessage msg = server.CreateMessage();
                    msg.Write((byte) PacketTypes.Headers.ReadyUpdate);
                    msg.Write(inc.SenderConnection.RemoteUniqueIdentifier);
                    msg.Write(playerStatus);
                    server.SendToAll(msg, NetDeliveryMethod.ReliableOrdered);
                    break;
                case PacketTypes.Headers.LoggedIn:
                    string username = inc.ReadString();
                    Player newPlayer = NewPlayer(inc, server, username);
                    Console.WriteLine(Players.Count);
                    if (Players.Count == 0)
                    {
                        Console.WriteLine("Sending {0} host packet", newPlayer.Name);
                        NetOutgoingMessage hMessage = server.CreateMessage();
                        hMessage.Write((byte) PacketTypes.Headers.YouAreHost);
                        server.SendMessage(hMessage, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered);
                    }

                    Players.Add(inc.SenderConnection.RemoteUniqueIdentifier, newPlayer);
                    Players[inc.SenderConnection.RemoteUniqueIdentifier].Connection = inc.SenderConnection;
                    break;
                case PacketTypes.Headers.ChatSend:
                    if (Players[inc.SenderConnection.RemoteUniqueIdentifier].Name != _drawer)
                    {
                        NetOutgoingMessage chatMessageRelay = server.CreateMessage();
                        string chatM = inc.ReadString();
                        chatMessageRelay.Write((byte) PacketTypes.Headers.ChatReceive);
                        chatMessageRelay.Write(Players[inc.SenderConnection.RemoteUniqueIdentifier].Name);
                        chatMessageRelay.Write(chatM);
                        if (!_badwordList.Contains(chatM, StringComparer.OrdinalIgnoreCase))
                        {
                            server.SendToAll(chatMessageRelay, NetDeliveryMethod.ReliableOrdered);
                        }
                        if (String.Equals(chatM, _theWord, StringComparison.CurrentCultureIgnoreCase) & chatM != null)
                        {
                            NetOutgoingMessage someoneOne = server.CreateMessage();
                            someoneOne.Write((byte) PacketTypes.Headers.ChatReceive);
                            someoneOne.Write("Server");
                            someoneOne.Write(Players[inc.SenderConnection.RemoteUniqueIdentifier].Name
                                             + " has guessed the correct word being: " + _theWord);
                            server.SendToAll(someoneOne, NetDeliveryMethod.ReliableOrdered);
                            RoundTimer.Stop();
                            StartNewRound(server);
                        }
                    }
                    break;
                case PacketTypes.Headers.PictureUpdate:
                    int r = inc.ReadVariableInt32();
                    int g = inc.ReadVariableInt32();
                    int b = inc.ReadVariableInt32();
                    int x = inc.ReadVariableInt32();
                    int y = inc.ReadVariableInt32();
                    int size = inc.ReadVariableInt32();
                    NetOutgoingMessage msgPicture = server.CreateMessage();
                    msgPicture.Write((byte) PacketTypes.Headers.PictureUpdate);
                    msgPicture.WriteVariableInt32(r);
                    msgPicture.WriteVariableInt32(g);
                    msgPicture.WriteVariableInt32(b);
                    msgPicture.WriteVariableInt32(x);
                    msgPicture.WriteVariableInt32(y);
                    msgPicture.WriteVariableInt32(size);
                    server.SendToAll(msgPicture, NetDeliveryMethod.ReliableOrdered);
                    break;
                case PacketTypes.Headers.StartGame:
                    NetOutgoingMessage msgStart = server.CreateMessage();
                    msgStart.Write((byte) PacketTypes.Headers.StartGame);
                    server.SendToAll(msgStart, NetDeliveryMethod.ReliableOrdered);
                    RoundTimer.Enabled = true;
                    StartNewRound(server);
                    break;
                case PacketTypes.Headers.DrawLine:
                {
                    int r1 = inc.ReadVariableInt32();
                    int g1 = inc.ReadVariableInt32();
                    int b1 = inc.ReadVariableInt32();
                    int x1 = inc.ReadVariableInt32();
                    int y1 = inc.ReadVariableInt32();
                    int size1 = inc.ReadVariableInt32();
                    int x11 = inc.ReadVariableInt32();
                    int y11 = inc.ReadVariableInt32();
                    NetOutgoingMessage msgDrawLine = server.CreateMessage();
                    msgDrawLine.Write((byte) PacketTypes.Headers.DrawLine);
                    msgDrawLine.WriteVariableInt32(r1);
                    msgDrawLine.WriteVariableInt32(g1);
                    msgDrawLine.WriteVariableInt32(b1);
                    msgDrawLine.WriteVariableInt32(x1);
                    msgDrawLine.WriteVariableInt32(y1);
                    msgDrawLine.WriteVariableInt32(size1);
                    msgDrawLine.WriteVariableInt32(x11);
                    msgDrawLine.WriteVariableInt32(y11);
                    server.SendToAll(msgDrawLine, NetDeliveryMethod.ReliableOrdered);
                }
                    break;
            }
        }