示例#1
0
 public void SendCurrentWorld(ServerPlayer player)
 {
     _outmsg = _netserver.CreateMessage();
     _outmsg.Write((byte)PacketType.WorldMapSize);
     _outmsg.Write(_mineserver.MapManager.Mapsize);
     _netserver.SendMessage(_outmsg, player.NetConn, NetDeliveryMethod.ReliableOrdered);
 }
示例#2
0
 public void SendInitialUpdate(ServerPlayer player)
 {
     _outmsg = _netserver.CreateMessage();
     _outmsg.Write((byte)PacketType.PlayerInitialUpdate);
     _outmsg.Write(player.Id);
     _outmsg.Write(player.Name);
     _outmsg.Write(player.Position);
     _netserver.SendMessage(_outmsg, player.NetConn, NetDeliveryMethod.ReliableOrdered);
 }
示例#3
0
 public void SendNameSet(ServerPlayer player)
 {
     _outmsg = _netserver.CreateMessage();
     _outmsg.Write((byte)PacketType.PlayerMovementUpdate);
     _outmsg.Write(player.Id);
     _outmsg.Write(player.Name);
     foreach (ServerPlayer dummy in _mineserver.PlayerManager.PlayerList.Values)
     {
         _netserver.SendMessage(_outmsg, dummy.NetConn, NetDeliveryMethod.ReliableOrdered);
     }
 }
示例#4
0
        public NetConnection GetConnectionByPlayer(ServerPlayer play)
        {
            foreach (ServerPlayer dummy in PlayerList.Values)
            {
                if (play == dummy)
                {
                    return dummy.NetConn;
                }
            }

            return null;
        }
示例#5
0
        public void Start()
        {
            NetIncomingMessage packetin;
            while (true)
            {
                while ((packetin = _netserver.ReadMessage()) != null)
                {
                    _msgSender = packetin.SenderConnection;
                    switch (packetin.MessageType)
                    {
                        case NetIncomingMessageType.StatusChanged:
                            {
                                NetConnectionStatus status = (NetConnectionStatus)packetin.ReadByte();
                                //Player doesnt want to play anymore
                                if (status == NetConnectionStatus.Disconnected || status == NetConnectionStatus.Disconnecting)
                                {
                                    _mineserver.Console.ConsoleWrite(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender).Name + " Disconnected");
                                    _mineserver.ServerSender.SendPlayerLeft(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                    _mineserver.PlayerManager.RemovePlayer(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                }
                                break;
                            }
                        case NetIncomingMessageType.DiscoveryRequest:
                            {
                                _mineserver.ServerSender.SendDiscoverResponse(packetin.SenderEndpoint);
                                break;
                            }
                        case NetIncomingMessageType.ConnectionApproval:
                            {
                                //If the server is full then deny
                                if (_netserver.ConnectionsCount == _netserver.Configuration.MaximumConnections)
                                {
                                    _msgSender.Deny("serverfull");
                                    break;
                                }

                                int version = packetin.ReadInt32();
                                string name = packetin.ReadString();

                                //If the version is any other then the server deny
                                if(_mineserver.VersionMatch(version) == false)
                                {
                                    _msgSender.Deny("versionmismatch");
                                    break;
                                }

                                ServerPlayer dummy = new ServerPlayer(_msgSender);
                                if (_mineserver.PlayerManager.NameExists(name))
                                {
                                    name += dummy.Id;
                                }

                                dummy.Name = name;
                                _mineserver.PlayerManager.AddPlayer(dummy);
                                _msgSender.Approve();
                                Thread.Sleep(4000);
                                _mineserver.GameWorld.GenerateSpawnPosition(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                _mineserver.ServerSender.SendCurrentWorld(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                _mineserver.ServerSender.SendInitialUpdate(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                _mineserver.ServerSender.SendPlayerJoined(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                _mineserver.ServerSender.SendOtherPlayersInWorld(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                _mineserver.Console.ConsoleWrite(name + " Connected");
                                break;
                            }
                        case NetIncomingMessageType.Data:
                            {
                                PacketType dataType = (PacketType)packetin.ReadByte();

                                switch (dataType)
                                {
                                    case PacketType.PlayerMovementUpdate:
                                        {
                                            _mineserver.PlayerManager.GetPlayerByConnection(_msgSender).Position = packetin.ReadVector3();
                                            _mineserver.ServerSender.SendMovementUpdate(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                                            break;
                                        }
                                    case PacketType.PlayerBlockSet:
                                        {
                                            Vector3 pos = packetin.ReadVector3();
                                            _mineserver.MapManager.WorldMap[(int)pos.X, (int)pos.Y, (int)pos.Z] = (BlockTypes)packetin.ReadByte();
                                            break;
                                        }
                                }
                                break;
                            }
                    }
                }
            }
        }
示例#6
0
 public void KickPlayer(ServerPlayer player)
 {
     //We dont need to remove the player here cause its handled in the serverlistener on status changed
     player.NetConn.Disconnect("kicked");
 }
示例#7
0
 public void AddPlayer(ServerPlayer play)
 {
     PlayerList.Add(play.NetConn, play);
 }
示例#8
0
 public void SetPlayerName(ServerPlayer player, string name)
 {
     foreach (ServerPlayer dummy in PlayerList.Values)
     {
         if (dummy == player)
         {
             dummy.Name = name;
         }
     }
 }
示例#9
0
 public void RemovePlayer(ServerPlayer play)
 {
     if(PlayerList.ContainsValue(play))
     {
         PlayerList.Remove(play.NetConn);
     }
 }
示例#10
0
 public void AddPlayer(ServerPlayer play)
 {
     PlayerList.Add(play.NetConn, play);
 }
示例#11
0
 public void BanPlayer(ServerPlayer player)
 {
     //We dont need to remove the player here cause its handled in the serverlistener on status changed
     player.NetConn.Disconnect("banned");
 }
示例#12
0
        public void Start()
        {
            NetIncomingMessage packetin;

            while (true)
            {
                while ((packetin = _netserver.ReadMessage()) != null)
                {
                    _msgSender = packetin.SenderConnection;
                    switch (packetin.MessageType)
                    {
                    case NetIncomingMessageType.StatusChanged:
                    {
                        NetConnectionStatus status = (NetConnectionStatus)packetin.ReadByte();
                        //Player doesnt want to play anymore
                        if (status == NetConnectionStatus.Disconnected || status == NetConnectionStatus.Disconnecting)
                        {
                            _mineserver.Console.ConsoleWrite(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender).Name + " Disconnected");
                            _mineserver.ServerSender.SendPlayerLeft(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                            _mineserver.PlayerManager.RemovePlayer(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                        }
                        break;
                    }

                    case NetIncomingMessageType.DiscoveryRequest:
                    {
                        _mineserver.ServerSender.SendDiscoverResponse(packetin.SenderEndpoint);
                        break;
                    }

                    case NetIncomingMessageType.ConnectionApproval:
                    {
                        //If the server is full then deny
                        if (_netserver.ConnectionsCount == _netserver.Configuration.MaximumConnections)
                        {
                            _msgSender.Deny("serverfull");
                            break;
                        }

                        int    version = packetin.ReadInt32();
                        string name    = packetin.ReadString();

                        //If the version is any other then the server deny
                        if (_mineserver.VersionMatch(version) == false)
                        {
                            _msgSender.Deny("versionmismatch");
                            break;
                        }

                        ServerPlayer dummy = new ServerPlayer(_msgSender);
                        if (_mineserver.PlayerManager.NameExists(name))
                        {
                            name += dummy.Id;
                        }

                        dummy.Name = name;
                        _mineserver.PlayerManager.AddPlayer(dummy);
                        _msgSender.Approve();
                        Thread.Sleep(4000);
                        _mineserver.GameWorld.GenerateSpawnPosition(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                        _mineserver.ServerSender.SendCurrentWorld(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                        _mineserver.ServerSender.SendInitialUpdate(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                        _mineserver.ServerSender.SendPlayerJoined(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                        _mineserver.ServerSender.SendOtherPlayersInWorld(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                        _mineserver.Console.ConsoleWrite(name + " Connected");
                        break;
                    }

                    case NetIncomingMessageType.Data:
                    {
                        PacketType dataType = (PacketType)packetin.ReadByte();

                        switch (dataType)
                        {
                        case PacketType.PlayerMovementUpdate:
                        {
                            _mineserver.PlayerManager.GetPlayerByConnection(_msgSender).Position = packetin.ReadVector3();
                            _mineserver.ServerSender.SendMovementUpdate(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
                            break;
                        }

                        case PacketType.PlayerBlockSet:
                        {
                            Vector3 pos = packetin.ReadVector3();
                            _mineserver.MapManager.WorldMap[(int)pos.X, (int)pos.Y, (int)pos.Z] = (BlockTypes)packetin.ReadByte();
                            break;
                        }
                        }
                        break;
                    }
                    }
                }
            }
        }
示例#13
0
 public void SendOtherPlayersInWorld(ServerPlayer player)
 {
     foreach (ServerPlayer dummy in _mineserver.PlayerManager.PlayerList.Values)
     {
         if (player.Id != dummy.Id)
         {
             _outmsg = _netserver.CreateMessage();
             _outmsg.Write((byte)PacketType.PlayerJoined);
             _outmsg.Write(dummy.Id);
             _outmsg.Write(dummy.Name);
             _outmsg.Write(dummy.Position);
             _outmsg.Write(dummy.Heading);
             _netserver.SendMessage(_outmsg, player.NetConn, NetDeliveryMethod.ReliableOrdered);
         }
     }
 }