Beispiel #1
0
        public void OnChatMessage(ref PacketReader _pReader, PacketType pt, ref ClientManager _client)
        {
            string message = _pReader.ReadString();
            ChatMessagePacket ChatMessage = new ChatMessagePacket(PacketType.ChatMessage);
            ChatMessage.MessageRecieved = message;
            ChatMessage.MessageSent = "";
            if (message[0] == '/' && (bool)Config.Configuration["EnableEmbeddedChatCommands"])
            {
                string command = message.Substring(1, message.Length - 1).ToLower();
                string[] commands = command.Split(' ');
                switch (commands[0])
                {
                    case "save":
                        ChatMessage.MessageSent = _client._player.name + ": " + "Saving World....";
                        World.SaveWorld();
                        ChatMessage.MessageSent = _client._player.name + ": " + "World Saved!";
                        break;
                    case "set":
                        switch (commands[1])
                        {
                            case "-b":
                                switch (commands[2])
                                {
                                    case "1":
                                        break;
                                    case "2":
                                        break;
                                    case "3":
                                        break;
                                    case "4":
                                        break;
                                }
                                break;
                        }
                        break;
                    default:
                        ChatMessage.MessageSent = "There is no such command please try again!";
                        break;
                }

                string[] data = command.Split((" ").ToCharArray());
                // command.Split((" ").ToCharArray());
                switch (data[0])
                {
                    case "tp":
                        bool UniqueUserNames = true;

                        PlayerClass player1 = null, player2 = null;

                        foreach (ClientManager _user1 in GridServer.player_list)
                        {
                            if ((_user1 != null) && (_user1._player.name.ToLower().StartsWith(data[1])))
                            {
                                if (player1 == null)
                                {
                                    player1 = _user1._player;
                                }
                                else
                                {
                                    UniqueUserNames = false;
                                    break;
                                }
                            }
                            if ((_user1 != null) && (_user1._player.name.ToLower().StartsWith(data[2])))
                            {
                                if (player2 == null)
                                {
                                    player2 = _user1._player;
                                }
                                else
                                {
                                    UniqueUserNames = false;
                                    break;
                                }
                            }
                        }

                        if (player1 != null & player2 != null & UniqueUserNames == true)
                        {
                            player2.position = player1.position;

                            PlayerPositionAndLookPacket tp_packet = new PlayerPositionAndLookPacket(PacketType.PlayerPositionLook);

                            tp_packet.OnGround = player2.onGround;
                            tp_packet.Pitch = player2.Pitch;
                            tp_packet.Stance = player2.stance;
                            tp_packet.X = player2.position.X;
                            tp_packet.Y = player2.position.Y;
                            tp_packet.Z = player2.position.Z;
                            tp_packet.Yaw = player2.Yaw;

                            tp_packet.BuildPacket();

                            _client.SendPacket((PacketHandler)tp_packet, _client.id, ref _client, false, false);
                            ChatMessage.MessageSent = player1.name + " teleported to " + player2.name;

                        }
                        else
                        {
                            ChatMessage.MessageSent = _client._player.name + ": " + "Cannot find user/wrong syntax";
                            GridServer.SendToPlayer((PacketHandler)ChatMessage, _client.id);
                        }
                        break;

                    case "kick":
                        foreach (ClientManager _user1 in GridServer.player_list)
                        {
                            if ((_user1 != null) && (_user1._player.name.ToLower().StartsWith(data[1])) && _user1._player.Rank <= RankLevel.Moderator)
                            {
                                DisconnectKick dk_packet = new DisconnectKick(PacketType.Disconnect_Kick);
                                dk_packet.Reason = "You have been kicked by " + _client._player.name + ", bitch!";
                                dk_packet.BuildPacket();
                                ClientManager test = _user1;
                                _client.SendPacket((PacketHandler)dk_packet, _user1.id, ref test, false, false);
                            }
                        }
                       break;
                    default:
                       //ChatMessage.MessageSent = "There is no such command please try again!";
                       break;

                }

                try
                {
                    int i = 0;
                    for (; i < base.ModuleAddons.Count; i++)
                    {
                        ChatMessage = (ChatMessagePacket)base.ModuleAddons.ElementAt(i).Value(pt, ModuleAddons.ElementAt(i).Key, ref _pReader, (PacketHandler)ChatMessage, ref _client);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR: " + e.Message + " Source:" + e.Source + " Method:" + e.TargetSite + " Data:" + e.Data);
                }
                if (ChatMessage.MessageSent == null || ChatMessage.MessageSent == "")
                {
                    ChatMessage.BuildPacket();
                    _client.SendPacket((PacketHandler)ChatMessage, _client.id, ref _client, false, false);
                }
                else
                {
                    ChatMessage.BuildPacket();
                    _client.SendPacket((PacketHandler)ChatMessage, _client.id, ref _client, false, false);
                }
            }
            else
            {
                ChatMessage.MessageSent = _client._player.name + ": " + message;
                ChatMessage.BuildPacket();
                ClientManager[] player = GridServer.player_list;
                for (int i = 0; i < player.Length; i++)
                {
                    if (player[i] == null)
                    {

                    }
                    else
                    {
                        if (player[i] == null)
                        {

                        }
                        else
                        {
                            player[i].SendPacket((PacketHandler)ChatMessage, player[i].id, ref player[i], false, false);
                        }
                    }
                }
            }
        }
        public void DoChunks()
        {
            try
            {
                base._ptype = PacketType.PreChunk;
                //base.
                base.RunModuleCache();
                Thread.Sleep(10); //Were sleeping because well the original client is to damn slow. LOL
                RunPreChunkInitialization();
                GridServer.player_list[_client.id].PreChunkRan = 1;
                Thread.Sleep(1000); //Were sleeping because well the original client is to damn slow. LOL
                for (int i = 0; i < base.ModuleAddons.Count; i++)
                {
                    //ModuleAddons
                    base.ModuleAddons.ElementAt(i).Value(PacketType.PreChunk, ModuleAddons.ElementAt(i).Key, ref pr, null, ref _client);
                }
                #region SendSpawn

                NamedEntitySpawnPacket EntitySpawn = new NamedEntitySpawnPacket(PacketType.NamedEntitySpawn);
                EntitySpawn.X = (int)_client._player.position.X * 32;
                EntitySpawn.Y = (int)_client._player.position.Y * 32;
                EntitySpawn.Z = (int)_client._player.position.Z * 32;
                EntitySpawn.EntityID = _client.id;
                EntitySpawn.PlayerName = _client._player.name;
                EntitySpawn.CurrentItem = 0;
                EntitySpawn.Pitch = (byte)_client._player.Pitch;
                EntitySpawn.Rotation = (byte)_client._player.stance;
                EntitySpawn.BuildPacket();

                foreach (string key in Config.Configuration.Keys)
                {
                    if (key.Contains("WelcomeMessage"))
                    {
                        ChatMessagePacket chatMsg = new ChatMessagePacket(PacketType.ChatMessage);
                        chatMsg.MessageSent = "SERVER: " + ((string)Config.Configuration[key]).Replace("%USER", _client._player.name);
                        chatMsg.BuildPacket();
                        _client.SendPacket((PacketHandler)chatMsg, _client.id, ref _client, false, false);
                    }
                }
                //int index_me = Chunk.GetIndex((int)cm._player.position.X, (int)cm._player.position.Y, (int)cm._player.position.Z);
                Thread.SpinWait(1);
                ClientManager[] player = GridServer.player_list;
                for (int i = 0; i < player.Length; i++)
                {
                    if (player[i] == null)
                    {

                    }
                    else
                    {
                        if (_client._client == null || _client._client.Connected == false || player[i].PreChunkRan != 1)
                        {
                            if (player[i] != null)
                            {
                                //return _p;
                            }
                        }
                        else
                        {
                            NamedEntitySpawnPacket t_EntitySpawn = new NamedEntitySpawnPacket(PacketType.NamedEntitySpawn);
                            t_EntitySpawn.X = (int)player[i]._player.position.X * 32;
                            t_EntitySpawn.Y = (int)player[i]._player.position.Y * 32;
                            t_EntitySpawn.Z = (int)player[i]._player.position.Z * 32;
                            t_EntitySpawn.EntityID = player[i].id;
                            t_EntitySpawn.PlayerName = player[i]._player.name;
                            t_EntitySpawn.CurrentItem = 0;
                            t_EntitySpawn.Pitch = (byte)(int)player[i]._player.Pitch;
                            t_EntitySpawn.Rotation = (byte)(int)player[i]._player.stance;
                            t_EntitySpawn.BuildPacket();
                            if (_client.id != player[i].id)
                                _client.SendPacket(t_EntitySpawn, _client.id, ref _client, false, false);
                            if (_client.id != player[i].id)
                                player[i].SendPacket(EntitySpawn, player[i].id, ref player[i], false, false);
                        }
                    }
                }
                try
                {
                    send.Abort();
                }
                catch (Exception)
                {
                    send.Abort();
                }
            }
            catch (Exception)
            {
                send.Abort();
            }
            //SendChunks(5, 2);
                #endregion SendSpawn
        }