Exemple #1
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);
        }
Exemple #2
0
 public void SendClient(Client client, IgorrMessage message)
 {
     connection.SendMessage(message.GetMessage(), client.Connection, NetDeliveryMethod.ReliableOrdered, currentChannel);
 }