Exemple #1
0
        public static void GetData(GetDataEventArgs e)
        {
            if (e.Handled)
                return;
            try
            {
                switch (e.MsgID)
                {
                    #region player join
                    case PacketTypes.TileGetSection:
                        {
                            if (!TShock.Players[e.Msg.whoAmI].RequestedSection)
                            {
                                lock (PlayerList)
                                {
                                    PlayerList.Add(new ATPlayer(e.Msg.whoAmI));
                                }
                                LoginThread lt = new LoginThread(e.Msg.whoAmI);
                                Thread t = new Thread(new ThreadStart(lt.CheckLogin));
                                t.Start();
                            }
                            break;
                        }
                    #endregion
                    #region Tile Edit
                    case PacketTypes.Tile:
                        {
                            byte type, tileType, style;
                            Int32 x, y;
                            bool fail;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                type = reader.ReadByte();
                                x = reader.ReadInt32();
                                y = reader.ReadInt32();
                                tileType = reader.ReadByte();
                                fail = reader.ReadBoolean();
                                style = reader.ReadByte();
                                reader.Close();
                                reader.Dispose();
                            }
                            int signID = Sign.ReadSign(x, y);
                            //Console.WriteLine("TileEdit: type: {0}, tiletype: {1}, fail: {2}, style: {3}, tile.frameX: {4}", type, tileType, fail, style, Main.tile[x, y].frameX);
                            //  Tile tile = Main.tile[x, y];
                            //    Console.WriteLine("Tileinfo: type: {0}, frameX: {1}, frameY: {2}, frameNum: {3}", tile.type, tile.frameX, tile.frameY, tile.frameNumber);
                            //   Console.WriteLine("Tiledata: type: {0}, frameX: {1}, frameY: {2}, frameNum: {3}", tile.Data.type, tile.Data.frameX, tile.Data.frameY, tile.Data.frameNumber);
                            //    Console.WriteLine("type: {0}, Main.tile[].active: {1}, fail: {2}", type, Main.tile[x, y].Data.active, fail);
                            #region Tile Remove
                            if (type == 0 || type == 4)
                            {
                                if (tileType == 0 && signID != -1)
                                {
                                    db.QueryReader("DELETE FROM SignData WHERE X=@0 AND Y=@1 AND WorldID=@2", x, y, Main.worldID);
                                }
                            }
                            #endregion
                            #region Tile place
                            else if (type == 1)
                            {

                            }
                            #endregion
                            break;
                        }
                    #endregion
                    #region Sign Edit
                    case PacketTypes.SignNew:
                        {
                            Int16 signId;
                            Int32 x, y;
                            byte[] textB;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                signId = reader.ReadInt16();
                                x = reader.ReadInt32();
                                y = reader.ReadInt32();
                                textB = reader.ReadBytes(e.Length - 10);
                                reader.Close();
                                reader.Dispose();
                            }
                            string newtxt = Encoding.UTF8.GetString(textB);
                            var tplayer = TShock.Players[e.Msg.whoAmI];
                            int id = Sign.ReadSign(x, y);
                            if (id != -1)
                            {
                                try
                                {
                                    lock (db)
                                    {
                                        var values = new List<SqlValue>();
                                        values.Add(new SqlValue("X", x));
                                        values.Add(new SqlValue("Y", y));
                                        values.Add(new SqlValue("User", "'" + tplayer.Name + "'"));
                                        values.Add(new SqlValue("Time", DateTime.Now.Ticks));
                                        values.Add(new SqlValue("WorldID", Main.worldID));
                                        SQLeditor.InsertValues("SignData", values);
                                        /*System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
                                        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("INSERT INTO user (infoDate) VALUES (@value)", conn);
                                        cmd.Parameters.AddWithValue("@value", DateTime.Now);
                                        cmd.ExecuteNonQuery();*/
                                    }
                                }
                                catch (Exception ex)
                                { Log.ConsoleError(ex.ToString()); }
                            }
                            break;
                        }
                    #endregion
                    #region Sign Read
                    case PacketTypes.SignRead:
                        {
                            int x, y;
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                x = reader.ReadInt32();
                                y = reader.ReadInt32();

                                reader.Close();
                            }
                            var id = Sign.ReadSign(x, y);
                            var tplayer = TShock.Players[e.Msg.whoAmI];
                            if (tplayer != null && id != -1)
                            {
                                if (tplayer.Group.HasPermission("AT.signhistory"))
                                {
                                    QueryResult query = db.QueryReader("Select User,Time from SignData where X=@0 AND Y=@1 AND WorldID=@2", x, y, Main.worldID);
                                    tplayer.SendMessage(String.Format("Sign edit history:"), Color.LightSalmon);
                                    while (query.Read())
                                    {
                                        long time = query.Get<long>("Time");
                                        tplayer.SendMessage(String.Format("{0} @ {1}", query.Get<string>("User"), new DateTime(time)), Color.BurlyWood);
                                    }
                                    query.Dispose();
                                }
                            }
                            // Console.WriteLine("x: {0} y: {1}", x, y);
                            break;
                        }
                    #endregion
                    #region Player Update
                    case PacketTypes.PlayerUpdate:
                        {
                            using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
                            {
                                var reader = new BinaryReader(data);
                                byte plyID = reader.ReadByte();
                                byte flags = reader.ReadByte();
                                byte item = reader.ReadByte();
                                float posX = reader.ReadSingle();
                                float posY = reader.ReadSingle();
                                float velX = reader.ReadSingle();
                                float velY = reader.ReadSingle();
                                reader.Close();
                                reader.Dispose();
                                //Console.WriteLine("PlayerUpdate: playerID: {0}, item: {1}, posX: {2}, posY: {3}, velX: {4}, velY: {5}", plyID, item, posX, posY, velX, velY);
                                //Console.WriteLine("item info: Name: {0}, dmg: {1}, animation: {2}", Main.player[plyID].inventory[item].name, Main.player[plyID].inventory[item].damage, Main.player[plyID].inventory[item].useAnimation);
                                TSPlayer tsplayer = TShock.Players[plyID];
                                if (tsplayer == null)
                                    break;
                                ATPlayer player = GetPlayerByUserID(tsplayer.UserID);
                                if (player == null)
                                    break;
                                // Console.WriteLine("Flags: {0}", flags);
                                if ((flags & 32) == 32)
                                {
                                    try
                                    {
                                        var BT = player.GetBindTool(Main.player[plyID].inventory[item]);
                                        if (BT != null)
                                        {
                                            BT.DoCommand(tsplayer);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.ConsoleError(ex.ToString());
                                    }
                                    //Console.WriteLine("Player {0} used item: {1}", player.TSPlayer.Name, Main.player[plyID].inventory[item].name);
                                }
                            }
                            break;
                        }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemple #2
0
        public void OnChat(messageBuffer buffer, int who, string text, System.ComponentModel.HandledEventArgs args)
        {
            if (args.Handled)
                return;
            if (text.StartsWith("/login"))
            {
                if (text.Length > 7 && TShock.Players[who].UserID != -1)
                {
                    var player = GetPlayerByUserID(TShock.Players[who].UserID);
                    if (player != null)
                    {
                        try
                        {
                            AdminToolsMain.db.QueryReader("UPDATE PlayerData SET Nicknames=@1, IPs=@2, LastSeen=@3 WHERE UserID=@0", player.UserID, JsonConvert.SerializeObject(player.Nicknames, Formatting.None), JsonConvert.SerializeObject(player.IP, Formatting.None), DateTime.Now.Ticks);

                            lock (PlayerList)
                            {
                                PlayerList.Remove(player);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.ConsoleError(ex.ToString());
                        }
                    }
                    LoginThread lt = new LoginThread(who);
                    Thread t = new Thread(new ThreadStart(lt.CheckLogin));
                    t.Start();
                }
            }
        }