ReadUInt16() public method

Reads a 16 bit unsigned integer written using Write(UInt16)
public ReadUInt16 ( ) : UInt16
return System.UInt16
Example #1
0
 protected override void Read(NetIncomingMessage message)
 {
     x = message.ReadFloat();
     y = message.ReadFloat();
     rotation = message.ReadUInt16().FromNetworkRotation() * (180f / (float)Math.PI);
     type = message.ReadByte();
 }
 public override void Read(NetIncomingMessage msg)
 {
     Id = msg.ReadUInt16();
     int count = msg.ReadInt32();
     for(int i = 0; i < count; ++i)
         Cards.Add(msg.ReadString());
 }
 public static void readBytes(NetIncomingMessage data, ClientSprite cs)
 {
     data.ReadByte();
     cs.ID = data.ReadUInt32();
     cs.SpriteID = (SpriteIDs)data.ReadUInt16();
     cs.Position = new Microsoft.Xna.Framework.Vector2(data.ReadFloat(),data.ReadFloat());
     cs.Rotation = data.ReadFloat();
 }
Example #4
0
 protected override void Read(NetIncomingMessage message)
 {
     Name = message.ReadString();
     X = message.ReadFloat();
     Y = message.ReadFloat();
     rotation = message.ReadUInt16().FromNetworkRotation() * (180f / (float)Math.PI);
     Health = message.ReadByte() / (float)byte.MaxValue;
 }
Example #5
0
 protected override void Read(NetIncomingMessage message)
 {
     var length = message.ReadUInt16();
     Program = new short[length];
     for (var i = 0; i < length; i++)
     {
         Program[i] = message.ReadInt16();
     }
 }
Example #6
0
        protected override void Read(NetIncomingMessage message)
        {
            Items.Clear();

            var count = message.ReadUInt16();
            for (var i = 0; i < count; i++)
            {
                Items.Add(NetObject.ReadFromMessage(message));
            }
        }
 /// <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);
 }
 public override void OnAdvancedNetworkMessage(NetIncomingMessage msg)
 {
     if (msg.ReadByte() == 0)
     {
         this.lxLoot = new List<PreSeededLoot>();
         byte byCount = msg.ReadByte();
         for (int i = 0; i < (int)byCount; i++)
         {
             this.lxLoot.Add(new PreSeededLoot(msg.ReadUInt16(), (ItemCodex.ItemTypes)msg.ReadInt32(), new Vector2(msg.ReadFloat(), msg.ReadFloat())));
         }
     }
 }
        public override void Read(NetIncomingMessage msg)
        {
            int count = msg.ReadInt32();
            for(int i = 0; i < count; ++i)
            {
                ushort uid = msg.ReadUInt16();
                List<string> cards = new List<string>();

                int cardCount = msg.ReadInt32();
                for(int j = 0; j < cardCount; ++j)
                    cards.Add(msg.ReadString());

                Options.Add(new Tuple<ushort, List<string>>(uid, cards));
            }
        }
Example #10
0
        public static Packet Get(NetIncomingMessage message)
        {
            var packetId = message.ReadUInt16();
            var pdata = PacketFactory.GetPacketType(packetId);

            var newPacket = (Packet)Activator
                .CreateInstance(pdata.PacketType);

            if (newPacket != null)
            {
                Bitstream stream = new Bitstream(message);
                newPacket.Deserialize(stream);
                return newPacket;
            }

            //TODO
            return null;
        }
Example #11
0
        public override void HandleData(NetIncomingMessage msg)
        {
            NetEntityType Type;
            ushort ID;
            Vector3 Position;
            Vector3 Velocity;
            Quaternion Orientation;
            NetMsgType datatype = (NetMsgType)msg.ReadByte();
            switch (datatype)
            {
                case NetMsgType.Chat:
                    Console.WriteLine(msg.ReadString());
                    break;
                case NetMsgType.CreateOnClient:
                    #region CreateOnClient
                    Type = (NetEntityType)msg.ReadByte();
                    ID = msg.ReadUInt16();
                    Position = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    Orientation = new Quaternion(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    ushort Resource;
                    long OwnerID;

                    //DEBUG
                    if (Type == NetEntityType.Ship)
                    {
                        int[] shipWeapons = null;
                        var shipNose = msg.ReadInt32();
                        var shipCore = msg.ReadInt32();
                        var shipTail = msg.ReadInt32();
                        int weaponLength = msg.ReadInt32();
                        if (weaponLength > 0)
                        {
                            shipWeapons = new int[weaponLength];
                            for (int i = 0; i < weaponLength; i++)
                                shipWeapons[i] = msg.ReadInt32();
                        }
                        Resource = 0;
                        OwnerID = msg.ReadInt64();
                        var shipData = new ShipData(shipNose, shipCore, shipTail);
                        WeaponsFromData(shipData, shipWeapons);
                        var ship = new ShipObj(MobileFortressClient.Game, Position, Orientation, shipData);
                        ship.ID = ID;
                        if (OwnerID == Network.Client.UniqueIdentifier)
                        {
                            Network.JoinedGame = true;
                            Camera.Setup(MobileFortressClient.Game, ship, new Vector3(0, 2f, 6f));
                            var HUD = new ShipHUD();
                            if (shipWeapons != null)
                            {
                                for (int i = 0; i < shipWeapons.Length; i++)
                                {
                                    HUD.MakeAmmoIndicator(shipWeapons[i]);
                                }
                            }
                            MenuManager.Menu = HUD;
                        }
                    }
                    else
                    {
                        Resource = msg.ReadUInt16();
                        if (Type == NetEntityType.Building)
                        {
                            new Building(Position, Resource);
                        }
                        else if (Type == NetEntityType.Missile)
                        {
                            var obj = new Rocket(MobileFortressClient.Game, Resource, Position, Orientation);
                            obj.ID = ID;
                        }
                        else
                        {
                            var obj = new PhysicsObj(MobileFortressClient.Game, Position, Orientation, Resource);
                            obj.ID = ID;
                        }
                    }
                    #endregion
                    break;
                case NetMsgType.MapLoading:
                    #region MapLoading
                    if (msg.ReadByte() == 0)
                    {
                        var Seed = msg.ReadInt32();
                        var Power = msg.ReadInt32();
                        var Roughness = msg.ReadFloat();
                        Sector.Redria.Terrain.Terrain = new Heightmap(Seed, Power, Roughness);
                    }
                    else
                    {
                        var terrain = Sector.Redria.Terrain.Terrain;
                        int alterations = msg.ReadInt32();
                        Console.WriteLine(alterations + " Recieved Alterations.");
                        for (int i = 0; i < alterations; i++)
                        {
                            Rectangle flattenedArea = new Rectangle(msg.ReadInt32(),
                                msg.ReadInt32(), msg.ReadInt32(), msg.ReadInt32());
                            terrain.FlattenArea(flattenedArea);

                        }
                        terrain.Graphics.ResetVertexBuffer();

                    }
                    #endregion
                    break;
                case NetMsgType.EntityUpdate:
                    #region EntityUpdate
                    Type = (NetEntityType)msg.ReadByte();
                    ID = msg.ReadUInt16();
                    Position = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    Velocity = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    Orientation = new Quaternion(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    if (Type == NetEntityType.Ship)
                    {
                        var ship = Sector.Redria.Ships.Retrieve(ID);
                        if (ship == null)
                        {
                            Console.WriteLine("No such ship ID: " + ID);
                            break;
                        }
                        ship.UpdateFromNet(Position, Orientation, Velocity);
                    }
                    else if (Type == NetEntityType.Missile)
                    {
                        var missile = Sector.Redria.Objects.Retrieve(ID);
                        if (missile == null) break;
                        missile.UpdateFromNet(Position, Orientation, Velocity);
                    }
                    #endregion
                    break;
                case NetMsgType.Bullet:
                    #region Bullet
                    ID = msg.ReadUInt16();
                    Position = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    Velocity = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    Orientation = new Quaternion(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                    var Projectile = ProjectileData.ProjectileTable[ID];
                    var ping = Network.Client.ServerConnection.AverageRoundtripTime;
                    Projectile.Create(Position + Velocity * (ping / 2), Orientation, Velocity);
                    var Audio = new AudioEmitter();
                    Audio.Position = Position / Resources.AudioPositionQuotient;
                    Audio.Forward = Vector3.Transform(Vector3.Forward, Orientation);
                    Audio.Up = Vector3.Up;
                    Audio.Velocity = Velocity;

                    var sound = Resources.Sounds.WeaponSounds[ID].CreateInstance();
                    sound.Apply3D(Camera.Audio, Audio);
                    sound.Play();
                    #endregion
                    break;
                case NetMsgType.ShipExplode:
                    #region ShipExplode
                    ID = msg.ReadUInt16();
                    var deadship = Sector.Redria.Ships.Retrieve(ID);
                    deadship.Explode();
                    #endregion
                    break;
                case NetMsgType.Explosion:
                    #region Explosion
                    ID = msg.ReadUInt16();
                    var Radius = msg.ReadFloat();
                    var exploding = Sector.Redria.Objects.Retrieve(ID);
                    if (exploding != null)
                    {
                        new Explosion(exploding.Position, Radius);
                        exploding.Destroy();
                    }
                    #endregion
                    break;
                case NetMsgType.Lockon:
                    #region Lockon
                    if (!(MenuManager.Menu is ShipHUD))
                        break;
                    ID = msg.ReadUInt16();
                    var LockonStatus = (LockonStatus)msg.ReadByte();
                    ShipHUD Menu = (ShipHUD)MenuManager.Menu;
                    if (LockonStatus > LockonStatus.Locked)
                    {
                        if (LockonStatus == LockonStatus.EnemyLock)
                        {
                            Menu.enemyLock = true;
                        }
                        else if (LockonStatus == LockonStatus.EnemyMissile)
                        {
                            Menu.enemyLock = false;
                            Menu.enemyMissile = true;
                        }
                        else
                        {
                            Menu.enemyMissile = false;
                            Menu.enemyLock = false;
                        }
                    }
                    else
                    {
                        if (ID == ushort.MaxValue)
                        {
                            Menu.Target = null;
                            Menu.LockStatus = LockonStatus.NotLocked;
                        }
                        else
                        {
                            Menu.Target = Sector.Redria.Ships.Retrieve(ID);
                            Menu.LockStatus = LockonStatus;
                            if (Menu.LockStatus == LockonStatus.Locking)
                                Resources.Sounds.LockingOn.Play();
                            else if (Menu.LockStatus == LockonStatus.Locked)
                                Resources.Sounds.LockedOn.Play();
                        }
                    }
                    #endregion
                    break;

                case NetMsgType.ShipUpdate:
                    #region ShipUpdate
                    var Health = msg.ReadFloat();
                    var Throttle = msg.ReadFloat();
                    var AmmoCount = msg.ReadByte();
                    var Ammo = new ushort[AmmoCount];
                    for (byte i = 0; i < AmmoCount; i++)
                    {
                        Ammo[i] = msg.ReadUInt16();
                    }
                    if (MenuManager.Menu is ShipHUD)
                    {
                        var HUD = (ShipHUD)MenuManager.Menu;
                        HUD.SetHealth((int)Health);

                        for (int i = 0; i < Ammo.Length; i++)
                            HUD.SetAmmo(i, Ammo[i]);
                        ping = msg.SenderConnection.AverageRoundtripTime * 1000;
                        HUD.SetPing(ping);

                        var ship = (ShipObj)Camera.Target;
                        ship.SetThrottle(Throttle);
                    }

                    #endregion
                    break;
                default:
                    Console.WriteLine("Unhandled NetMsgType: " + datatype);
                    break;
            }
        }
Example #12
0
 public override void OnAdvancedNetworkMessage(NetIncomingMessage msg)
 {
     if (msg.ReadByte() == 0)
     {
         FlagCodex.FlagID enFlag = (FlagCodex.FlagID)msg.ReadUInt16();
         this.HandleFlagTrigger(enFlag);
     }
 }
Example #13
0
 public virtual NetworkMessage Read(NetIncomingMessage msgIn)
 {
     type = (NetworkMessageType)msgIn.ReadUInt16();
     return this;
 }
Example #14
0
        private void HandleRegisterHost(NetIncomingMessage inc)
        {
            var id = inc.ReadInt64();
            var name = inc.ReadString();
            var population = inc.ReadUInt16();
            var maxPopulation = inc.ReadUInt16();
            var guid = inc.ReadString();
            var endpoint = inc.ReadIPEndpoint();
            var game = inc.ReadInt32();

            //if (manager.Register(id, new Guid(guid)))
            {
                registeredHosts[id] = new Object[]
                {
                    endpoint,
                    inc.SenderEndpoint,
                    name,
                    population,
                    maxPopulation,
                    NetTime.Now,
                    game
                };
            }
        }
Example #15
0
        private void HandleDataMessage(NetIncomingMessage incomingMessage)
        {
            if (IsAuthenticated)
            {
                //incomingMessage.Decrypt(cryptoAlgorithm);
            }

            var p = incomingMessage.ReadProtocol();
            ushort messageType = incomingMessage.ReadUInt16();

            //Trace.WriteLine("Received " + ((CustomMessageType)messageType).ToString() + ".");

            var protocol = Protocols.Where(x => x.Equals(p)).First();

            var mHandlers = GetHandlers(protocol, messageType);
            var message = protocol.Create(messageType);
            message.ReadPayload(incomingMessage);

            if (OnMessageReceived != null)
                OnMessageReceived(null, new MessageEventArgs(this, message));

            if (mHandlers != null)
            {
                for (int n = 0; n < mHandlers.Count; ++n)
                    mHandlers[n](new MessageEventArgs(this, message));
            }
        }
Example #16
0
 private static void Consume(NetIncomingMessage msg)
 {
     try
     {
         //faster than switch, as this is in most to least common order
         if (msg.SequenceChannel == Channels.UNRELIABLE_STREAM)
         {
             var actorId = msg.ReadUInt16();
             NetworkView find;
             if (NetworkView.Find(actorId, out find))
                 find.OnDeserializeStream(msg);
         }
         else if (msg.SequenceChannel == Channels.RELIABLE_STREAM)
         {
             var actorId = msg.ReadUInt16();
             NetworkView find;
             if (NetworkView.Find(actorId, out find))
                 find.OnDeserializeStream(msg);
         }
         else if (msg.SequenceChannel >= Channels.BEGIN_RPCMODES && msg.SequenceChannel <= Channels.OWNER_RPC)
         {
             //rpc...
             var viewID = msg.ReadUInt16();
             var rpcId = msg.ReadByte();
             NetworkView find;
             if (NetworkView.Find(viewID, out find))
                 find.CallRPC(rpcId, msg);
             else
                 Debug.LogWarning("couldn't find view " + viewID + " to send rpc " + rpcId);
         }
         else if (msg.SequenceChannel == Channels.SYNCHED_FIELD)
         {
             var viewId = msg.ReadUInt16();
             var fieldId = msg.ReadByte();
             NetworkView find;
             if (NetworkView.Find(viewId, out find))
                 find.SetSynchronizedField(fieldId, msg);
             else
                 Debug.LogWarning("couldn't find view " + viewId + " to set field " + fieldId);
         }
         else if (msg.SequenceChannel == Channels.OBJECT_RPC)
         {
             var viewId = msg.ReadUInt16();
             var rpcId = msg.ReadByte();
             NetworkedSceneObject find;
             if (NetworkedSceneObject.sceneObjects.TryGetValue(viewId, out find))
                 find.CallRPC(rpcId, msg);
         }
         else if (msg.SequenceChannel == Channels.STATIC_RPC)
         {
             var rpcId = msg.ReadByte();
             ProcessRPC(rpcId, msg);
         }
         else if (msg.SequenceChannel == Channels.STATIC_UTILS)
         {
             ProcessUtils(msg);
         }
         else
         {
             Debug.LogWarning("data received over unhandled channel " + msg.SequenceChannel);
         }
     }
     catch (Exception er)
     {
         Debug.LogError(er.Message + er.StackTrace);
     }
 }
Example #17
0
        private void HandleData(GameTime gameTime, NetIncomingMessage msg)
        {
            MessageType messageType = (MessageType)msg.ReadByte();

            switch (messageType)
            {
                case MessageType.MsgState:
                    {
                        Log.DebugFormat("Got MsgState ({0} bytes)", msg.LengthBytes);

                        // we finished receiving state at this point
                        ServerLinkStatus = NetServerLinkStatus.Connected;

                        break;
                    }

                case MessageType.MsgAddPlayer:
                    {
                        Log.DebugFormat("Got MsgAddPlayer ({0} bytes)", msg.LengthBytes);

                        MsgAddPlayerPacket packet = MsgAddPlayerPacket.Read(msg);

                        FireMessageEvent(gameTime, packet);

                        break;
                    }

                case MessageType.MsgRemovePlayer:
                    {
                        Log.DebugFormat("Got MsgRemovePlayer ({0} bytes)", msg.LengthBytes);

                        MsgRemovePlayerPacket packet = MsgRemovePlayerPacket.Read(msg);

                        FireMessageEvent(gameTime, packet);

                        break;
                    }

                case MessageType.MsgWorld:
                    {
                        Log.DebugFormat("Got MsgWorld ({0} bytes)", msg.LengthBytes);

                        UInt16 mapLength = msg.ReadUInt16();
                        Byte[] rawWorld = new Byte[mapLength];
                        msg.ReadBytes(mapLength, out rawWorld);

                        MemoryStream ms = new MemoryStream(rawWorld);
                        StreamReader sr = new StreamReader(ms);

                        MsgWorldPacket msgWorldEventData = new MsgWorldPacket(mapLength, sr);

                        FireMessageEvent(gameTime, msgWorldEventData);

                        break;
                    }

                case MessageType.MsgPlayerServerUpdate:
                    {
                        MsgPlayerServerUpdatePacket packet = MsgPlayerServerUpdatePacket.Read(msg);

                        FireMessageEvent(gameTime, packet);

                        break;
                    }

                default:
                    // if we get anything else we should fail
                    // protocol version should protect us from unknowns
                    break;

            }
        }
Example #18
0
 public virtual void OnAdvancedNetworkMessage(NetIncomingMessage msg)
 {
     Game1 master = Program.GetTheGame();
     if (master.xNetworkInfo.enCurrentRole == NetworkHelperInterface.NetworkRole.Client)
     {
         byte byType = msg.ReadByte();
         if (byType == 0)
         {
             if (this.xView != master.xLocalPlayer)
             {
                 return;
             }
             ItemCodex.ItemTypes enItemType = (ItemCodex.ItemTypes)msg.ReadInt32();
             master._Item_CreateItemGetWatcher(this.xView, enItemType, 180, 1, false);
             return;
         }
         else
         {
             if (byType == 1)
             {
                 ushort iEnemyID = msg.ReadUInt16();
                 this.TryCatch(Program.GetTheGame().dixEnemyList[iEnemyID].xBehaviour);
                 return;
             }
             if (byType == 2)
             {
                 if (this.xView != master.xLocalPlayer)
                 {
                     return;
                 }
                 this.EnterMiniGame();
                 return;
             }
             else if (byType == 4)
             {
                 if (master.xLocalPlayer == this.xView)
                 {
                     return;
                 }
                 this.EndCatch();
                 return;
             }
         }
     }
     else if (master.xNetworkInfo.enCurrentRole == NetworkHelperInterface.NetworkRole.Server)
     {
         byte byType2 = msg.ReadByte();
         if (byType2 == 0)
         {
             ItemCodex.ItemTypes enItemType2 = (ItemCodex.ItemTypes)msg.ReadInt32();
             master._Enemies_CallFromFeedingPlayer(this.xView, enItemType2);
             master._Item_CreateItemGetWatcher(this.xView, enItemType2, 180, 1, true);
             NetOutgoingMessage om = this.CreateMessage();
             om.Write(0);
             om.Write((int)enItemType2);
             this.SendMessage(om);
             return;
         }
         if (byType2 == 3)
         {
             byte byCatchChoise = msg.ReadByte();
             Program.GetTheGame()._Enemy_TurnEnemyIntoPet(this.xView, this.xBehaviour.xOwner, byCatchChoise == 0);
             return;
         }
         if (byType2 == 4)
         {
             this.EndCatch();
         }
     }
 }
Example #19
0
 public void ReadFrom(NetIncomingMessage br)
 {
     this.enNPCType = (NPCCodex.NPCTypes)br.ReadInt32();
     this.sName = br.ReadString();
     this.iLevel = (int)br.ReadByte();
     this.bySkin = br.ReadByte();
     this.deniStatLevels[PetInfo.PetBonus.HP] = br.ReadUInt16();
     this.deniStatLevels[PetInfo.PetBonus.SP] = br.ReadUInt16();
     this.deniStatLevels[PetInfo.PetBonus.Damage] = br.ReadUInt16();
     this.deniStatLevels[PetInfo.PetBonus.Crit] = br.ReadUInt16();
     this.deniStatLevels[PetInfo.PetBonus.Speed] = br.ReadUInt16();
     this.xDescription = PetCodex.GetDescription(this.enNPCType);
     this.CalculateBonusValues();
     Program.GetTheGame()._Pet_AddPetBonuses(this);
 }
 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 #21
0
        private static void ProcessUtils(NetIncomingMessage msg)
        {
            var utilId = msg.ReadByte();

            if (utilId == RPCUtils.TimeUpdate)
            {

            }
            else if (utilId == RPCUtils.Instantiate)
            {
                //read the path...
                var resourcePath = msg.ReadString();
                if (Debug.isDebugBuild)
                    Debug.Log("network instantiate of " + resourcePath);
                var viewId = msg.ReadUInt16();
                var ownerId = msg.ReadUInt16();

                GameObject gobj;
                bool isCached = false;
                if (resourceCaching && (isCached = ResourceCache.ContainsKey(resourcePath)))
                    gobj = ResourceCache[resourcePath];
                else
                    gobj = Resources.Load(resourcePath) as GameObject;

                if (resourceCaching && !isCached)
                    ResourceCache.Add(resourcePath, gobj);

                var instance = (GameObject)GameObject.Instantiate(gobj);

                if (instance == null)
                {
                    Debug.LogWarning("could not find prefab " + resourcePath + " to instantiate");
                    return;
                }

                var trans = instance.transform;

                trans.position = Vector3Serializer.Deserialize(msg);
                trans.rotation = QuaternionSerializer.Deserialize(msg);
                if (Debug.isDebugBuild)
                {
                    Debug.Log(string.Format("network instantiate of {0}. Loc: {1} Rot: {2}", resourcePath, trans.position, trans.rotation));
                }

                //look for a networkview..

                var view = instance.GetComponent<NetworkView>();

                if (view)
                {
                    NetworkView.RegisterView(view, viewId);
                    view.viewID = new NetworkViewId() { guid = viewId, IsMine = PlayerId == ownerId};
                    view.IsMine = PlayerId == ownerId;
                    view.OwnerId = ownerId;

                    var nBehaviours = instance.GetComponents<NetBehaviour>();

                    foreach (var behave in nBehaviours)
                    {
                        behave.netView = view;

                        view.OnFinishedCreation += behave.CallFinished;
                    }

                    view.OnFinishedCreation();

                    FinishedInstantiate(view.viewID.guid);
                }
            }
            else if (utilId == RPCUtils.Remove)
            {
                var viewId = msg.ReadUInt16();

                NetworkView find;
                if (NetworkView.Find(viewId, out find))
                {
                    find.OnRemove();
                }

                NetworkView.RemoveView(viewId);
            }
            else if (utilId == RPCUtils.ChangeRoom)
            {
                var newRoom = msg.ReadString();

                NetworkedSceneObject.sceneObjects = new Dictionary<int, NetworkedSceneObject>();
                OnRoomChange(newRoom);
            }
            else if (utilId == RPCUtils.SetPlayerId)
            {
                var playerId = msg.ReadUInt16();
                PlayerId = playerId;
                if (Debug.isDebugBuild)
                    Debug.Log("Setting player id to " + playerId);
            }
        }
Example #22
0
 public void ReadInfo(NetIncomingMessage msg)
 {
     this.xOwner.xRenderComponent.SwitchAnimation(msg.ReadUInt16(), Animation.CancelOptions.IgnoreIfPlaying);
     this.enCurrentAction = (GundamHandAI.GundamHandAction)msg.ReadInt32();
     this.iCounter = msg.ReadInt32();
     this.xOwner.xTransform.v2Pos = new Vector2(msg.ReadFloat(), msg.ReadFloat());
 }
Example #23
0
        private void HandleUnconnectedDataMessage(NetIncomingMessage message)
        {
            var p = message.ReadProtocol();
            ushort messageType = message.ReadUInt16();

            //Trace.WriteLine("Received " + ((CustomMessageType)messageType).ToString() + " unconnected.");

            var protocol = Protocols.Where(x => x.Equals(p)).First();

            var mHandlers = GetUnconnectedHandlers(protocol, messageType);
            var customMessage = protocol.Create(messageType);
            customMessage.ReadPayload(message);

            if (OnUnconnectedMessageReceived != null)
                OnUnconnectedMessageReceived(null, new UnconnectedMessageEventArgs(customMessage, message.SenderEndpoint));

            if (mHandlers != null)
            {
                for (int n = 0; n < mHandlers.Count; ++n)
                    mHandlers[n](new UnconnectedMessageEventArgs(customMessage, message.SenderEndpoint));
            }
        }
        private void HandleStartPlacement(NetIncomingMessage msg)
        {
            CurrentPermission = new PlacementInformation
                                    {
                                        Range = msg.ReadInt32(),
                                        IsTile = msg.ReadBoolean()
                                    };

            var mapMgr = (MapManager) IoCManager.Resolve<IMapManager>();

            if (CurrentPermission.IsTile) CurrentPermission.TileType = msg.ReadUInt16();
            else CurrentPermission.EntityType = msg.ReadString();
            CurrentPermission.PlacementOption = msg.ReadString();

            BeginPlacing(CurrentPermission);
        }
Example #25
0
 public void ReadData(NetIncomingMessage data)
 {
     this.iOwnerItemID = data.ReadUInt16();
     for (int i = 0; i < this.aiFurnitureIDs.Length; i++)
     {
         int iX = i % this.aiFurnitureIDs.GetLength(0);
         int iY = i / this.aiFurnitureIDs.GetLength(1);
         this.aiFurnitureIDs[iX, iY] = data.ReadUInt16();
     }
 }
Example #26
0
        internal static void ProcessUtils(NetIncomingMessage msg)
        {
            //
            var utilId = msg.ReadByte();

            if (utilId == RPCUtils.TimeUpdate)
            {
                //Players shouldn't be doing this either..
            }
            else if (utilId == RPCUtils.Instantiate)
            {
                //Players shouldn't be instantiating things

                //read the path...

                //var resourcePath = msg.ReadString();
                //var viewId = msg.ReadUInt16();
                //var ownerId = msg.ReadUInt16();

                //var gobj = Resources.Load(resourcePath);
                //var instance = (GameObject)GameObject.Instantiate(gobj);

                //look for a networkview..

                //var view = instance.GetComponent<NetworkView>();

                //if (view)
                //{
                //    NetworkView.RegisterView(view, viewId);
                //    view.viewID = new NetworkViewId() { guid = viewId, IsMine = PlayerId == ownerId };
                //}
            }
            else if (utilId == RPCUtils.FinishedRoomChange)
            {
                //the player has finished loading into the new room. now actually put their player in the new room.

                var player = msg.SenderConnection.Tag as Player;

                var newRoom = player.GetRoomSwitchingTo();

                if (newRoom != null)
                {
                    newRoom.AddPlayer(player);
                }
            }
            else if (utilId == RPCUtils.Remove)
            {
                //Players shouldn't be removing view ids

                //var viewId = msg.ReadUInt16();

                //NetworkView.RemoveView(viewId);
            }
            else if (utilId == RPCUtils.FinishedInstantiate)
            {
                Player player = msg.SenderConnection.Tag as Player;
                ushort viewId = msg.ReadUInt16();

                NetworkView find;
                if (NetworkView.Find(viewId, out find))
                {
                    find.gameObject.OnFinishedInstantiate(player);
                }
            }
        }
 public override void OnAdvancedNetworkMessage(NetIncomingMessage msg)
 {
     byte byID = msg.ReadByte();
     if (CAS.NetworkRole == NetworkHelperInterface.NetworkRole.Client && byID == 1)
     {
         long iPlayerID = msg.ReadInt64();
         if (Program.game.dixPlayers.ContainsKey(iPlayerID))
         {
             this.FireDelayedHomingBulletClient(Program.game.dixPlayers[iPlayerID], msg.ReadInt32(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadUInt16());
         }
     }
 }
Example #28
0
        private static void Consume(NetIncomingMessage msg)
        {
            try
            {
                //faster than switch, as this is in most to least common order
                if (msg.SequenceChannel == Channels.UNRELIABLE_STREAM)
                {
                    var actorId = msg.ReadUInt16();
                    NetworkView find;
                    if (NetworkView.Find(actorId, out find))
                    {
                        Player player = GetPlayer(msg.SenderConnection);
                        find.OnDeserializeStream(msg, player);
                    }
                }
                else if (msg.SequenceChannel == Channels.RELIABLE_STREAM)
                {
                    var actorId = msg.ReadUInt16();
                    NetworkView find;
                    if (NetworkView.Find(actorId, out find))
                    {
                        Player player = GetPlayer(msg.SenderConnection);
                        find.OnDeserializeStream(msg, player);
                    }
                }
                else if (msg.SequenceChannel >= Channels.BEGIN_RPCMODES && msg.SequenceChannel <= Channels.OWNER_RPC)
                {
                    //rpc...
                    var viewID = msg.ReadUInt16();
                    var rpcId = msg.ReadByte();
                    Player player = GetPlayer(msg.SenderConnection);
                    NetworkView find;
                    var info = new NetMessageInfo((RPCMode)(msg.SequenceChannel - Channels.BEGIN_RPCMODES), player);
                    if (NetworkView.Find(viewID, out find))
                    {
                        find.CallRPC(rpcId, msg, info);

                        //Do we need to forward this still?
                        if (info.mode != RPCMode.Server && info.continueForwarding)
                        {
                            //need to forward...
                            if (info.mode == RPCMode.Others || info.mode == RPCMode.All) { }
                            else
                            {
                                find.Buffer(msg);
                            }
                            find.Send(msg, info.mode, msg.SenderConnection);
                        }
                    }

                }
                else if (msg.SequenceChannel == Channels.SYNCHED_FIELD)
                {
                    var viewId = msg.ReadUInt16();
                    var fieldId = msg.ReadByte();
                    NetworkView find;
                    if (NetworkView.Find(viewId, out find))
                    {
                        find.BufferField(msg, fieldId);
                        find.SendField(msg, msg.SenderConnection);
                    }
                }
                else if (msg.SequenceChannel == Channels.OBJECT_RPC)
                {
                    Player player = GetPlayer(msg.SenderConnection);
                    if (player.CurrentRoom != null)
                        player.CurrentRoom.IncomingObjectRPC(msg);
                }
                else if (msg.SequenceChannel == Channels.STATIC_RPC)
                {
                    var rpcId = msg.ReadByte();

                    var player = GetPlayer(msg.SenderConnection);
                    var currentRoom = player.CurrentRoom;
                    if (currentRoom != null)
                    {
                        NetMessageInfo info = new NetMessageInfo(RPCMode.None, player);
                        currentRoom.CallRPC(rpcId, msg, info);

                        if (info.continueForwarding)
                        {
                            var newMessage = peer.CreateMessage();
                            msg.Clone(newMessage);
                            currentRoom.SendMessage(newMessage);
                        }
                    }

                }
                else if (msg.SequenceChannel == Channels.STATIC_UTILS)
                {
                    ProcessUtils(msg);
                }
                else
                {
                    Debug.LogWarning("data received over unhandled channel " + msg.SequenceChannel);
                }
            }
            catch (Exception ex)
            {
                Debug.Log("[Consumption] {0} : {1}", ex.Message, ex.StackTrace);
            }
        }
 public override void Read(NetIncomingMessage msg)
 {
     Id = msg.ReadUInt16();
 }
        public void HandlePlacementRequest(NetIncomingMessage msg)
        {
            string alignRcv = msg.ReadString();

            Boolean isTile = msg.ReadBoolean();

            var mapMgr = (MapManager)IoCManager.Resolve<IMapManager>();

            ushort tileType = 0;

            string entityTemplateName = "";

            if (isTile) tileType = msg.ReadUInt16();
            else entityTemplateName = msg.ReadString();

            float xRcv = msg.ReadFloat();
            float yRcv = msg.ReadFloat();
            var dirRcv = (Direction) msg.ReadByte();

            IPlayerSession session = IoCManager.Resolve<IPlayerManager>().GetSessionByConnection(msg.SenderConnection);
            if (session.attachedEntity == null)
                return; //Don't accept placement requests from nobodys

            PlacementInformation permission = GetPermission(session.attachedEntity.Uid, alignRcv);
            Boolean isAdmin =
                IoCManager.Resolve<IPlayerManager>().GetSessionByConnection(msg.SenderConnection).adminPermissions.
                    isAdmin;

            float a = (float)Math.Floor(xRcv);
            float b = (float)Math.Floor(yRcv);
            Vector2 tilePos = new Vector2(a, b);

            if (permission != null || true)
                //isAdmin) Temporarily disable actual permission check / admin check. REENABLE LATER
            {
                if (permission != null)
                {
                    if (permission.Uses > 0)
                    {
                        permission.Uses--;
                        if (permission.Uses <= 0)
                        {
                            BuildPermissions.Remove(permission);
                            SendPlacementCancel(session.attachedEntity);
                        }
                    }
                    else
                    {
                        BuildPermissions.Remove(permission);
                        SendPlacementCancel(session.attachedEntity);
                        return;
                    }
                }

                if (!isTile)
                {
                    Entity created = _server.EntityManager.SpawnEntityAt(entityTemplateName, new Vector2(xRcv, yRcv));
                    if (created != null)
                    {
                        created.GetComponent<ITransformComponent>(ComponentFamily.Transform).TranslateTo(
                            new Vector2(xRcv, yRcv));
                        if(created.HasComponent(ComponentFamily.Direction))
                            created.GetComponent<IDirectionComponent>(ComponentFamily.Direction).Direction = dirRcv;
                        if(created.HasComponent(ComponentFamily.WallMounted))
                            created.GetComponent<IWallMountedComponent>(ComponentFamily.WallMounted).AttachToTile(mapMgr.GetTileRef(tilePos));
                    }
                }
                else
                {
                    mapMgr.Tiles[tilePos] = new Tile(tileType);
                }
            }
            else //They are not allowed to request this. Send 'PlacementFailed'. TBA
            {
                LogManager.Log("Invalid placement request: "
                               + IoCManager.Resolve<IPlayerManager>().GetSessionByConnection(msg.SenderConnection).name +
                               " - " +
                               IoCManager.Resolve<IPlayerManager>().GetSessionByConnection(msg.SenderConnection).
                                   attachedEntity.Uid.ToString() +
                               " - " + alignRcv.ToString());

                SendPlacementCancel(
                    IoCManager.Resolve<IPlayerManager>().GetSessionByConnection(msg.SenderConnection).attachedEntity);
            }
        }