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); } } }
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; } }
public BodyConfigurationMessage(IgorrMessage incoming) : base(incoming) { }
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); }
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); }
void HandleChat(IgorrMessage message) { ChatMessage cm = (ChatMessage)(message); Console.WriteLine("Chat: "+ cm.Text); }
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); }
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); } }
public static void HandleAssignPlayer(IgorrMessage message) { AssignPlayerMessage apm = (AssignPlayerMessage)message; manager.SelectPlayer(apm.objectID); }
public static void SendReliable(IgorrMessage m) { if (!_enabled) return; m.Encode(); if (connection.ServerConnection != null) connection.SendMessage(m.GetMessage(), NetDeliveryMethod.ReliableOrdered); }
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); }
public static void HandleStun(IgorrMessage message) { StunMessage sm = (StunMessage)message; Player player = manager.GetPlayer(sm.id); if (player != null) player.Stun(sm.stunTime); }
public static void HandleSpawnAttack(IgorrMessage message) { SpawnAttackMessage sam = (SpawnAttackMessage)message; manager.SpawnAttack(sam.position, sam.move, sam.id, sam.info,sam.attackID); }
public static void HandleSpawn(IgorrMessage message) { SpawnMessage sm = (SpawnMessage)message; manager.SpawnObject(sm.position,sm.move, sm.objectType, sm.id, sm.Info); }
public static void HandleShadows(IgorrMessage message) { ShadowMessage sm = (ShadowMessage)message; _gameRef.Shadows = sm.shadows; }
public JoinMessage(IgorrMessage m) : base(m) { }
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); } }
public static void HandleAttachAnimation(IgorrMessage message) { AttachAnimationMessage aam = (AttachAnimationMessage)message; Player player = manager.GetPlayer(aam.playerID); if (player != null) player.AttachAnimation(aam.animationFile); }
public void SendClient(Client client, IgorrMessage message) { connection.SendMessage(message.GetMessage(), client.Connection, NetDeliveryMethod.ReliableOrdered, currentChannel); }
public SpawnMessage(IgorrMessage m) : base(m) { }
void HandleAttack(IgorrMessage message) { AttackMessage am = (AttackMessage)(message); _clients[message.clientID].CurrentMap.ObjectManager.SpawnAttack(am.attackerID,am.attackDir, am.attackID, am.attackInfo); }
public ChangeTileMessage(IgorrMessage incoming) : base(incoming) { }
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); }
public PickupMessage(IgorrMessage incoming) : base(incoming) { }
void HandleLeave(IgorrMessage message) { LeaveMessage lm = (LeaveMessage)(message); Console.WriteLine("Leave Message: ClientID: " + message.clientID); RemoveClient(message.clientID); }
public ContainerMessage(IgorrMessage incoming) : base(incoming) { }
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); } }
public void AddMessage(IgorrMessage message) { _messages.Add(message); }
public SpawnAttackMessage(IgorrMessage m) : base(m) { }
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); }