ReadUInt64() public method

Reads a 64 bit unsigned integer written using Write(UInt64)
public ReadUInt64 ( ) : System.UInt64
return System.UInt64
Example #1
0
 public static new Packet FromNetBuffer(NetIncomingMessage incomingMessage)
 {
     var result =
         (GameMap) SerializationHelper.ByteArrayToObject(incomingMessage.ReadBytes(incomingMessage.ReadInt32()));
     var id = incomingMessage.ReadUInt64();
     var packet = new SendMapPacket(result, id);
     return packet;
 }
        public static new Packet FromNetBuffer(NetIncomingMessage incomingMessage)
        {
            // Read values back in
            var velocity = new Vector2(incomingMessage.ReadFloat(), incomingMessage.ReadFloat());
            var location = new Vector2(incomingMessage.ReadFloat(), incomingMessage.ReadFloat());
            var id = incomingMessage.ReadUInt64();

            var packet = new NotifyMovementPacket(velocity, location, id);
            return packet;
        }
 /// <summary>
 /// Handles an incoming entity component message
 /// </summary>
 /// <param name="message">Raw network message</param>
 /// <returns>An IncomingEntityComponentMessage object</returns>
 public IncomingEntityComponentMessage HandleEntityComponentNetworkMessage(NetIncomingMessage message)
 {
     var componentFamily = (ComponentFamily) message.ReadByte();
     var messageParams = new List<object>();
     while (message.Position < message.LengthBits)
     {
         switch ((NetworkDataType) message.ReadByte())
         {
             case NetworkDataType.d_enum:
                 messageParams.Add(message.ReadInt32());
                 break;
             case NetworkDataType.d_bool:
                 messageParams.Add(message.ReadBoolean());
                 break;
             case NetworkDataType.d_byte:
                 messageParams.Add(message.ReadByte());
                 break;
             case NetworkDataType.d_sbyte:
                 messageParams.Add(message.ReadSByte());
                 break;
             case NetworkDataType.d_ushort:
                 messageParams.Add(message.ReadUInt16());
                 break;
             case NetworkDataType.d_short:
                 messageParams.Add(message.ReadInt16());
                 break;
             case NetworkDataType.d_int:
                 messageParams.Add(message.ReadInt32());
                 break;
             case NetworkDataType.d_uint:
                 messageParams.Add(message.ReadUInt32());
                 break;
             case NetworkDataType.d_ulong:
                 messageParams.Add(message.ReadUInt64());
                 break;
             case NetworkDataType.d_long:
                 messageParams.Add(message.ReadInt64());
                 break;
             case NetworkDataType.d_float:
                 messageParams.Add(message.ReadFloat());
                 break;
             case NetworkDataType.d_double:
                 messageParams.Add(message.ReadDouble());
                 break;
             case NetworkDataType.d_string:
                 messageParams.Add(message.ReadString());
                 break;
             case NetworkDataType.d_byteArray:
                 int length = message.ReadInt32();
                 messageParams.Add(message.ReadBytes(length));
                 break;
         }
     }
     return new IncomingEntityComponentMessage(componentFamily, messageParams);
 }
Example #4
0
 public static void Read(Packets Packet, NetIncomingMessage I)
 {
     switch (Packet)
     {
         case Packets.Connection:
             if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
             {
                 ulong ClientVersion = I.ReadUInt64();
                 if (ClientVersion == Globe.Version)
                 {
                     Player Connector = Player.Add(new Player(I.ReadString()) { Connection = I.SenderConnection });
                     if (Connector != null)
                     {
                         MultiPlayer.Send("Game", MultiPlayer.Construct("Game", Packet, Connector.Slot, Connector.Name), I.SenderConnection);
                         List<object> Details = new List<object>();
                         for (byte i = 0; i < Players.Length; i++)
                             if ((Players[i] != null) && (Players[i] != Connector))
                             {
                                 Details.Add(true);
                                 Details.Add(Players[i].Name);
                             }
                             else Details.Add(false);
                         I.SenderConnection.Approve(MultiPlayer.Construct("Game", Packets.Initial, (byte)Players.Length, Connector.Slot, Details));
                     }
                     else I.SenderConnection.Deny("Full");
                 }
                 else I.SenderConnection.Deny("Version indifference, Client: " + ClientVersion + " - Server: " + Globe.Version);
             }
             else if (MultiPlayer.Type("Game") == MultiPlayer.Types.Client) { byte Slot = I.ReadByte(); Player.Set(Slot, new Player(I.ReadString())); }
             break;
         case Packets.Disconnection:
             Player Disconnector = ((MultiPlayer.Type("Game") == MultiPlayer.Types.Server) ? Player.Get(I.SenderConnection) :
                 ((MultiPlayer.Type("Game") == MultiPlayer.Types.Client) ? Players[I.ReadByte()] : null));
             if (Disconnector != null) Player.Remove(Disconnector);
             if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server) MultiPlayer.Send("Game", MultiPlayer.Construct("Game", Packets.Disconnection, Disconnector.Slot), I.SenderConnection);
             break;
         case Packets.Initial:
             if (MultiPlayer.Type("Game") == MultiPlayer.Types.Client)
             {
                 Players = new Player[I.ReadByte()];
                 Self = Player.Set(I.ReadByte(), new Player(MpName) { });
                 for (byte i = 0; i < Players.Length; i++)
                     if (I.ReadBoolean())
                     {
                         Players[i] = new Player(i, I.ReadString());
                     }
                 Timers.Add("Positions", (1 / 30d));
                 State = States.Game;
             }
             break;
         case Packets.Position:
             Player Sender = ((MultiPlayer.Type("Game") == MultiPlayer.Types.Server) ? Player.Get(I.SenderConnection) : null);
             Vector2 Position; float Angle;
             if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
             {
                 if (Sender != null)
                 {
                     Sender.Position = I.ReadVector2();
                     Sender.Angle = I.ReadFloat();
                 }
             }
             else if (MultiPlayer.Type("Game") == MultiPlayer.Types.Client)
             {
                 byte Count = (byte)((I.LengthBytes - 1) / 12);
                 for (byte i = 0; i < Count; i++)
                 {
                     Sender = Players[I.ReadByte()];
                     Position = I.ReadVector2();
                     Angle = I.ReadFloat();
                     if (Sender != null)
                     {
                         Sender.Position = Position;
                         Sender.Angle = Angle;
                     }
                 }
             }
             break;
     }
 }
 private List<object> UnPackParams(NetIncomingMessage message)
 {
     var messageParams = new List<object>();
     while (message.Position < message.LengthBits)
     {
         switch ((NetworkDataType) message.ReadByte())
         {
             case NetworkDataType.d_enum:
                 messageParams.Add(message.ReadInt32()); //Cast from int, because enums are ints.
                 break;
             case NetworkDataType.d_bool:
                 messageParams.Add(message.ReadBoolean());
                 break;
             case NetworkDataType.d_byte:
                 messageParams.Add(message.ReadByte());
                 break;
             case NetworkDataType.d_sbyte:
                 messageParams.Add(message.ReadSByte());
                 break;
             case NetworkDataType.d_ushort:
                 messageParams.Add(message.ReadUInt16());
                 break;
             case NetworkDataType.d_short:
                 messageParams.Add(message.ReadInt16());
                 break;
             case NetworkDataType.d_int:
                 messageParams.Add(message.ReadInt32());
                 break;
             case NetworkDataType.d_uint:
                 messageParams.Add(message.ReadUInt32());
                 break;
             case NetworkDataType.d_ulong:
                 messageParams.Add(message.ReadUInt64());
                 break;
             case NetworkDataType.d_long:
                 messageParams.Add(message.ReadInt64());
                 break;
             case NetworkDataType.d_float:
                 messageParams.Add(message.ReadFloat());
                 break;
             case NetworkDataType.d_double:
                 messageParams.Add(message.ReadDouble());
                 break;
             case NetworkDataType.d_string:
                 messageParams.Add(message.ReadString());
                 break;
             case NetworkDataType.d_byteArray:
                 int length = message.ReadInt32();
                 messageParams.Add(message.ReadBytes(length));
                 break;
         }
     }
     return messageParams;
 }
Example #6
0
		void OnActionPackage(NetIncomingMessage message)
		{
			Debug.Assert(Clients.ContainsKey(message.SenderConnection));

			try {
				while (message.Position < message.LengthBits) {
					ulong id = message.ReadUInt64();
					float time = message.ReadFloat();
					PlayerActionType type = (PlayerActionType)message.ReadByte();
					Vec2 position = new Vec2(message.ReadFloat(), message.ReadFloat());
					Vec2 target = ActionTypeHelper.IsSpell(type) ? new Vec2(message.ReadFloat(), message.ReadFloat()) : null;

					PlayerAction action = new PlayerAction(id, type, time, position, target);

					Clients[message.SenderConnection].ActionsPackage.Add(action);
				}
			} catch (Exception e) {
				ILogger.Log("Action package badly formatted: " + e.ToString(), LogPriority.Error);
			}
		}
 public static new Packet FromNetBuffer(NetIncomingMessage incomingMessage)
 {
     var entityID = incomingMessage.ReadUInt64();
         var packet = new EntityRemovePacket(entityID);
         return packet;
 }
Example #8
0
            private static Object ReadValue(NetIncomingMessage packet, TypeCode typeCode)
            {
                Object value;

                switch (typeCode)
                {
                    case TypeCode.Empty:
                        throw new NotSupportedException("Empty is not a supported type for variables");

                    case TypeCode.Object:
                        throw new NotSupportedException("Object is not a supported type for variables");

                    case TypeCode.DBNull:
                        throw new NotSupportedException("DBNull is not a supported type for variables");

                    case TypeCode.Boolean:
                        value = packet.ReadBoolean();
                        break;

                    case TypeCode.Char:
                        throw new NotSupportedException("Char is not a supported type for variables");

                    case TypeCode.SByte:
                        value = packet.ReadSByte();
                        break;

                    case TypeCode.Byte:
                        value = packet.ReadByte();
                        break;

                    case TypeCode.Int16:
                        value = packet.ReadInt16();
                        break;

                    case TypeCode.UInt16:
                        value = packet.ReadUInt16();
                        break;

                    case TypeCode.Int32:
                        value = packet.ReadInt32();
                        break;

                    case TypeCode.UInt32:
                        value = packet.ReadUInt32();
                        break;

                    case TypeCode.Int64:
                        value = packet.ReadInt64();
                        break;

                    case TypeCode.UInt64:
                        value = packet.ReadUInt64();
                        break;

                    case TypeCode.Single:
                        value = packet.ReadSingle();
                        break;

                    case TypeCode.Double:
                        value = packet.ReadDouble();
                        break;

                    case TypeCode.Decimal:
                        throw new NotSupportedException("Decimal is not a supported type for variables");

                    case TypeCode.DateTime:
                        throw new NotSupportedException("DateTime is not a supported type for variables");

                    case TypeCode.String:
                        value = packet.ReadString();
                        break;

                    default:
                        throw new NotSupportedException(String.Format("Unknown type {0} is not a supported type for variables", typeCode));
                }

                return value;
            }