Esempio n. 1
0
 protected override void Decode()
 {
     _numMessages = _incoming.ReadInt32();
     _messages = new List<IgorrMessage>();
     for (int x = 0; x < _numMessages; x++)
     {
         try
         {
             IgorrMessage m = new IgorrMessage(_incoming);
             _messages.Add(ProtocolHelper.DecodeMessage(m));
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
         }
     }
 }
Esempio n. 2
0
 public static void HandleSetHP(IgorrMessage message)
 {
     SetPlayerStatusMessage shpm = (SetPlayerStatusMessage)message;
     Player player = manager.GetPlayer(shpm.playerID);
     if (player != null)
     {
         player.MaxHP = shpm.maxHP;
         player.HP = shpm.currentHP;
         player.Exp = shpm.Exp;
         player.LastLevelExp = shpm.lastLevelExp;
         player.NextLevelExp = shpm.nextLevelExp;
     }
 }
Esempio n. 3
0
 public BodyConfigurationMessage(IgorrMessage incoming)
     : base(incoming)
 {
 }
Esempio n. 4
0
        void HandleMoveItem(IgorrMessage m)
        {
            MoveItemMessage mim = (MoveItemMessage)m;
            Client cl = _clients[mim.clientID];
            Player player = cl.CurrentMap.ObjectManager.GetPlayer(cl.PlayerID);
            if(player==null)
                return;
            Logic.Body.IPartContainer cont = Modules.ModuleManager.SpawnByIdServer(null, mim.id, -1, Point.Zero, null) as Logic.Body.IPartContainer;
            Logic.Body.BodyPart part = cont!=null?cont.Part:null;
            if (mim.To == MoveTarget.Body)
                player.Body.TryEquip(mim.Slot, part);
            if (mim.To == MoveTarget.Inventory)
                player.Inventory.Add(part);
            if (mim.From == MoveTarget.Body)
                player.Body.Unequip(part);
            if (mim.From == MoveTarget.Inventory)
                player.Inventory.Remove(part);

            MoveItemMessage nmim = (MoveItemMessage)ProtocolHelper.NewMessage(MessageTypes.MoveItem);
            nmim.PlayerID = player.ID;
            nmim.id = mim.id;
            nmim.Quantity = mim.Quantity;
            nmim.Slot = mim.Slot;
            nmim.To = mim.To;
            nmim.From = mim.From;
            nmim.Encode();
            SendAllExcept(cl.CurrentMap, player, nmim, true);
        }
Esempio n. 5
0
        void HandleJoin(IgorrMessage message)
        {
            JoinMessage jm = (JoinMessage)(message);

            if (Management.LoginData.CheckLogin(jm.Name, jm.Password))
            {
                Map targetMap = MapManager.GetMapByID(0);
                int id = targetMap.ObjectManager.getID();

                Player player = new Player(null, new Rectangle(0, 0, 16, 15), id);
                player.Name = jm.Name;

                Management.PlayerInfo pinfo = Management.ClientInfoInterface.GetInfo(player);
                targetMap = MapManager.GetMapByID(pinfo.Map);
                if(targetMap==null)
                    targetMap = MapManager.GetMapByID(0);

                Client client = new Client(message.SenderConnection, jm.Name, _protocolHelper);
                client.PlayerID = id;
                _clientids.Add(client.Connection.RemoteUniqueIdentifier, client.ID);
                _clients.Add(client.ID, client);
                _connections.Add(client.Connection);
                client.SetMap(targetMap, new Vector2(pinfo.PosX, pinfo.PosY));

                Point spawnPoint;
                if (pinfo.PosX == 0 && pinfo.PosY == 0)
                    spawnPoint = targetMap.getRandomSpawn();
                else spawnPoint = new Point(pinfo.PosX, pinfo.PosY);
                player = new Player(targetMap, new Rectangle((int)spawnPoint.X, (int)spawnPoint.Y, 16, 15), id);
                player.Name = jm.Name;
                targetMap.ObjectManager.Add(player);

                AssignPlayerMessage apm = (AssignPlayerMessage)ProtocolHelper.NewMessage(MessageTypes.AssignPlayer);
                apm.objectID = id;
                apm.Encode();
                SendClient(client, apm);

                if (pinfo.Parts != null)
                    for (int x = 0; x < pinfo.Parts.Count; x++)
                    {
                        GameObject obj = Modules.ModuleManager.SpawnByIdServer(null, pinfo.Parts[x], -1, Point.Zero, null);
                        Logic.Body.IPartContainer cont = obj as Logic.Body.IPartContainer;
                        if (cont == null)
                            continue;
                        player.GivePart(cont.Part);
                        PickupMessage pum = (PickupMessage)ProtocolHelper.NewMessage(MessageTypes.Pickup);
                        pum.PlayerID = player.ID;
                        pum.id = cont.Part.GetID();
                        pum.Encode();
                        SendAllMapReliable(client.CurrentMap, pum, true);
                    }

                for (int x = 0; x < targetMap.ObjectManager.Objects.Count; x++)
                {
                    Player play = targetMap.ObjectManager.Objects[x] as Player;
                    if (play != null && play!=player)
                    {
                        play.Body.SendBody(player);
                    }
                }

                Console.WriteLine(client.Name + " joined");
            }
            else
                Console.WriteLine("Invalid Login: Name: " + jm.Name + " Password: " + jm.Password);
        }
Esempio n. 6
0
 void HandleChat(IgorrMessage message)
 {
     ChatMessage cm = (ChatMessage)(message);
     Console.WriteLine("Chat: "+ cm.Text);
 }
Esempio n. 7
0
 public void SendClient(Player player, IgorrMessage message)
 {
     if (!message.Encoded)
     {
         Console.WriteLine("WARNING: Message not encoded: " + message.MessageType.ToString());
         message.Encode();
     }
     foreach (Client client in _clients.Values)
         if (client.PlayerID == player.ID)
             connection.SendMessage(message.GetMessage(), client.Connection, NetDeliveryMethod.ReliableOrdered,currentChannel);
 }
Esempio n. 8
0
 public void SendAllMapReliable(IMap map, IgorrMessage message, bool ordered)
 {
     List<NetConnection> recipients = new List<NetConnection>();
     recipients.AddRange(_connections);
     for (int x = 0; x < recipients.Count; x++)
     {
         if (_clients[_clientids[recipients[x].RemoteUniqueIdentifier]].CurrentMap != map)
         {
             recipients.RemoveAt(x);
             x--;
         }
     }
     if (!message.Encoded)
     {
         Console.WriteLine("WARNING: Message not encoded: " + message.MessageType.ToString());
         message.Encode();
     }
     if (recipients.Count > 0)
     {
         if (ordered)
             connection.SendMessage(message.GetMessage(), recipients, NetDeliveryMethod.ReliableOrdered, currentChannel);
         else
             connection.SendMessage(message.GetMessage(), recipients, NetDeliveryMethod.ReliableUnordered, currentChannel);
     }
 }
Esempio n. 9
0
 public static void HandleAssignPlayer(IgorrMessage message)
 {
     AssignPlayerMessage apm = (AssignPlayerMessage)message;
     manager.SelectPlayer(apm.objectID);
 }
Esempio n. 10
0
 public static void SendReliable(IgorrMessage m)
 {
     if (!_enabled)
         return;
     m.Encode();
     if (connection.ServerConnection != null)
             connection.SendMessage(m.GetMessage(), NetDeliveryMethod.ReliableOrdered);
 }
Esempio n. 11
0
 public static void Send(IgorrMessage message, bool Sequenced)
 {
     if (!_enabled)
         return;
     message.Encode();
     if (connection.ServerConnection != null)
         if (!Sequenced)
             connection.SendMessage(message.GetMessage(), NetDeliveryMethod.Unreliable);
         else
             connection.SendMessage(message.GetMessage(), NetDeliveryMethod.UnreliableSequenced);
         //ProtocolHelper.Send(message, connection.ServerConnection);
 }
Esempio n. 12
0
 public static void HandleStun(IgorrMessage message)
 {
     StunMessage sm = (StunMessage)message;
     Player player = manager.GetPlayer(sm.id);
     if (player != null)
         player.Stun(sm.stunTime);
 }
Esempio n. 13
0
 public static void HandleSpawnAttack(IgorrMessage message)
 {
     SpawnAttackMessage sam = (SpawnAttackMessage)message;
     manager.SpawnAttack(sam.position, sam.move, sam.id, sam.info,sam.attackID);
 }
Esempio n. 14
0
 public static void HandleSpawn(IgorrMessage message)
 {
     SpawnMessage sm = (SpawnMessage)message;
     manager.SpawnObject(sm.position,sm.move, sm.objectType, sm.id, sm.Info);
 }
Esempio n. 15
0
 public static void HandleShadows(IgorrMessage message)
 {
     ShadowMessage sm = (ShadowMessage)message;
     _gameRef.Shadows = sm.shadows;
 }
Esempio n. 16
0
 public JoinMessage(IgorrMessage m)
     : base(m)
 {
 }
Esempio n. 17
0
 public void SendAllExcept(IMap map, Player player, IgorrMessage message, bool Reliable)
 {
     Client client = getClient(player);
     if (_connections.Count > 1)
     {
         List<NetConnection> recipients = new List<NetConnection>();
         recipients.AddRange(_connections);
         if (client != null)
             recipients.Remove(client.Connection);
         for (int x = 0; x < recipients.Count; x++)
         {
             if (_clients[_clientids[recipients[x].RemoteUniqueIdentifier]].CurrentMap != map)
             {
                 recipients.RemoveAt(x);
                 x--;
             }
         }
         if (!message.Encoded)
         {
             Console.WriteLine("WARNING: Message not encoded: " + message.MessageType.ToString());
             message.Encode();
         }
         if (recipients.Count > 0 && Reliable)
             connection.SendMessage(message.GetMessage(), recipients, NetDeliveryMethod.ReliableOrdered, currentChannel);
         else if (recipients.Count > 0 && !Reliable && !_enableSend)
             connection.SendMessage(message.GetMessage(), recipients, NetDeliveryMethod.Unreliable, currentChannel);
     }
 }
Esempio n. 18
0
 public static void HandleAttachAnimation(IgorrMessage message)
 {
     AttachAnimationMessage aam = (AttachAnimationMessage)message;
     Player player = manager.GetPlayer(aam.playerID);
     if (player != null)
         player.AttachAnimation(aam.animationFile);
 }
Esempio n. 19
0
 public void SendClient(Client client, IgorrMessage message)
 {
     connection.SendMessage(message.GetMessage(), client.Connection, NetDeliveryMethod.ReliableOrdered, currentChannel);
 }
Esempio n. 20
0
 public SpawnMessage(IgorrMessage m)
     : base(m)
 {
 }
Esempio n. 21
0
 void HandleAttack(IgorrMessage message)
 {
     AttackMessage am = (AttackMessage)(message);
     _clients[message.clientID].CurrentMap.ObjectManager.SpawnAttack(am.attackerID,am.attackDir, am.attackID, am.attackInfo);
 }
Esempio n. 22
0
 public ChangeTileMessage(IgorrMessage incoming)
     : base(incoming)
 {
 }
Esempio n. 23
0
 void HandleInteract(IgorrMessage message)
 {
     InteractMessage im = (InteractMessage)message;
     Client cl = _clients[im.clientID];
     Player player = cl.CurrentMap.ObjectManager.GetPlayer(cl.PlayerID);
     GameObject obj = cl.CurrentMap.ObjectManager.GetObject(im.objectID);
     obj.Interact(player, im.sinfo, im.info);
 }
Esempio n. 24
0
 public PickupMessage(IgorrMessage incoming)
     : base(incoming)
 {
 }
Esempio n. 25
0
 void HandleLeave(IgorrMessage message)
 {
     LeaveMessage lm = (LeaveMessage)(message);
     Console.WriteLine("Leave Message: ClientID: " + message.clientID);
     RemoveClient(message.clientID);
 }
Esempio n. 26
0
 public ContainerMessage(IgorrMessage incoming)
     : base(incoming)
 {
 }
Esempio n. 27
0
 void HandlePosition(IgorrMessage message)
 {
     PositionMessage pm = (PositionMessage)(message);
     //Console.WriteLine("Position: id: " + pm.id.ToString() + " Position: " + pm.Position.ToString());
     Client client;
     if (_clients.TryGetValue(message.clientID, out client))
     {
         PositionMessage pm2 = (PositionMessage)ProtocolHelper.NewMessage(MessageTypes.Position);
         pm2.id = pm.id;
         pm2.Position = pm.Position;
         pm2.Move = pm.Move;
         pm2.Encode();
         if (client.CurrentMap.ObjectManager.UpdatePosition(pm.Position, pm.Move, pm.id, pm.TimeStamp))
             SendAllExcept(client.CurrentMap, client.CurrentMap.ObjectManager.GetPlayer(client.PlayerID), pm2, true);
     }
 }
Esempio n. 28
0
 public void AddMessage(IgorrMessage message)
 {
     _messages.Add(message);
 }
Esempio n. 29
0
 public SpawnAttackMessage(IgorrMessage m)
     : base(m)
 {
 }
Esempio n. 30
0
 public static void HandleSetGlow(IgorrMessage message)
 {
     SetGlowMessage sgm = (SetGlowMessage)message;
     if (_gameRef.Map != null)
         _gameRef.Light.SetGlow(sgm.id, sgm.Position, sgm.Color, sgm.radius, sgm.shadows);
 }