private bool DeserializeAsServer(BinaryReader reader, int senderPlayerId) { ChatMessage message = ChatMessage.Deserialize(reader); ChatManager.Commands.ProcessIncomingMessage(message, senderPlayerId); return(true); }
public DisconnectEventArgs(string reason, DateTime disconnectTime) : base(disconnectTime) { if (string.IsNullOrEmpty(reason)) { throw new ArgumentNullException(nameof(reason)); } this.rawJson = reason; this.Reason = ChatMessage.Deserialize(reason); }
private bool HandleNetModules(ref BinaryReader reader, int playernumber) { var moduleId = reader.ReadUInt16(); //LoadNetModule is now used for sending chat text. //Read the module ID to determine if this is in fact the text module if (Main.netMode == 2) { if (moduleId == Terraria.Net.NetManager.Instance.GetId <Terraria.GameContent.NetModules.NetTextModule>()) { //Then deserialize the message from the reader var msg = ChatMessage.Deserialize(reader); var splayer = Main.player[playernumber].GetServerPlayer(); if (msg.Text.StartsWith("/", StringComparison.Ordinal)) { return(true); } if (!splayer.IsLogin) { MessageSender.SendErrorMessage(playernumber, "你还没有登录,不能说话哦"); return(true); } var text = msg.Text; /*$"<{splayer.Group.ChatPrefix}>{Main.player[(int)playernumber].name}: {msg.Text}";*/ //NetPacket packet = NetTextModule.SerializeServerMessage(NetworkText.FromLiteral(text), // splayer.Group.ChatColor, (byte)playernumber); //NetManager.Instance.Broadcast(packet, -1); //MessageSender.SendChatMessageToClient(playernumber, Main.player[(int)playernumber].name, msg.Text, splayer.Group); MessageSender.SendChatMessageToClient(playernumber, Main.player[(int)playernumber].name, msg.Text, splayer.Group, splayer.qqAuth.CustomChatPrefix); CommandBoardcast.ConsoleNormalText($"<{splayer.Name}> : {text}"); return(true); } } //else if(Main.netMode == 1) //{ // if (moduleId == Terraria.Net.NetManager.Instance.GetId<Terraria.GameContent.NetModules.NetTextModule>()) // { // //Then deserialize the message from the reader // byte id = reader.ReadByte(); // string text = NetworkText.Deserialize(reader).ToString(); // Color c = reader.ReadRGB(); // if (id < 255 && text.Contains(':')) // { // Main.player[id].chatOverhead.NewMessage(text.Substring(text.IndexOf(':') + 1), Main.chatLength / 2); // // text = NameTagHandler.GenerateTag(Main.player[(int)b].name) + " " + text; // } // Main.NewTextMultiline(text, false, c, -1); // return true; // } //} return(false); }
/// <summary> /// Intercept chat messages sent from players. /// </summary> private bool NetTextModule_DeserializeAsServer(NetTextModule.orig_DeserializeAsServer orig, Terraria.GameContent.NetModules.NetTextModule self, BinaryReader reader, int senderPlayerId) { long savedPosition = reader.BaseStream.Position; ChatMessage message = ChatMessage.Deserialize(reader); if (Global.Config.ShowChatMessages) { Core.RaiseTerrariaMessageReceived(this, new TCRPlayer() { PlayerId = senderPlayerId, Name = Main.player[senderPlayerId].name }, message.Text); } reader.BaseStream.Position = savedPosition; return(orig(self, reader, senderPlayerId)); }
private bool HandleNetModules(ref BinaryReader reader, int playernumber) { var moduleId = reader.ReadUInt16(); //LoadNetModule is now used for sending chat text. //Read the module ID to determine if this is in fact the text module if (Main.netMode == 2) { if (moduleId == Terraria.Net.NetManager.Instance.GetId <Terraria.GameContent.NetModules.NetTextModule>()) { //Then deserialize the message from the reader var msg = ChatMessage.Deserialize(reader); return(msg.Text.StartsWith("/", StringComparison.Ordinal)); } } return(false); }