public void SendChat() { SoundManager.Instance.play(LoadManager.Instance.GetSFXData(SFXType.Tabsound).clip, AudioSettings.dspTime + Time.deltaTime, 0F, 1F); string chat = msg.text; if (isTime || string.IsNullOrEmpty(chat)) { return; } var info = GameManager.Instance.LocalPlayer.playerInfo; var packet = new SendChat(); packet.index = (int)info.Race - 1; packet.nick = info.Nickname; packet.msg = chat; packet.SendPacket(true); isTime = true; msg.text = ""; if (chat.IndexOf("/gold") != 0) { Instantiate(myChat, chatGrid).GetComponent <ChatData>().Initialize(info.Nickname, chat, chatStyles[(int)info.Race - 1], true); } StartCoroutine(Timer(0.5f)); StartCoroutine(FocusChat()); }
public void ChatMessage(SendChat schat) { var chat = new Chat { PlayerId = schat.ClientId, ChatMessage = schat.ChatMessage }; var msg = Serializer.SerializeItem(chat); foreach (var i in _clients) { Deserializer <Client> .InvokeMethodFromMessage(i.Value, msg); } }
public void SendChat(MsgPack pack) { SendChat data = pack.Msg.SendChat; PlayerData playerData = _cacheSvc.GetPlayerDataBySession(pack.Session); TaskSys.Instance.CalcTaskPrangs(playerData, 6); NetMsg netMsg = new NetMsg { cmd = (int)Command.PshChat, PshChat = new PshChat { Name = playerData.Name, Chat = data.Chat } }; List <ServerSession> list = _cacheSvc.GetOnLineServerSessions(); byte[] bytes = PENet.PETool.PackNetMsg(netMsg); foreach (var t in list) { t.SendMsg(bytes); } }
private GameOperationResponse HandleOperationSendChat(GameOperationRequest operationRequest) { var operation = new SendChat(server.Protocol, operationRequest); if (!operation.IsValid) { return new GameErrorResponse(operationRequest.OperationCode) { ReturnCode = (short)ResultCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() } } ; switch ((MessageType)operation.MessageType) { case MessageType.Group: { lock (joinedChannels) { var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Group); if (channel == null) { return new SendChatResponse(operation.OperationCode) { ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType } } ; // TODO: Normalize content and prevent spam var message = operation.Message; if (string.IsNullOrEmpty(message)) { return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty)); } channel.Publish(message, this); } } break; case MessageType.Guild: { lock (joinedChannels) { var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Guild); if (channel == null) { return new SendChatResponse(operation.OperationCode) { ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType } } ; // TODO: Normalize content and prevent spam var message = operation.Message; if (string.IsNullOrEmpty(message)) { return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty)); } channel.Publish(message, this); } } break; case MessageType.Local: { lock (joinedChannels) { var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Local); if (channel == null) { return new SendChatResponse(operation.OperationCode) { ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType } } ; // TODO: Normalize content and prevent spam var message = operation.Message; if (string.IsNullOrEmpty(message)) { return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty)); } channel.Publish(message, this); } } break; case MessageType.Trade: { lock (joinedChannels) { var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Trade); if (channel == null) { return new SendChatResponse(operation.OperationCode) { ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType } } ; // TODO: Normalize content and prevent spam var message = operation.Message; if (string.IsNullOrEmpty(message)) { return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty)); } channel.Publish(message, this); } } break; case MessageType.Tell: { var receiverName = operation.Receiver; if (string.IsNullOrEmpty(receiverName)) { return(operation.GetErrorResponse((short)ResultCode.PlayerNotFound)); } ChatSession receiver; if (!chat.SessionCache.TryGetSessionBySessionName(receiverName, out receiver)) { return(operation.GetErrorResponse((short)ResultCode.PlayerNotFound)); } // TODO: Normalize content and prevent spam var message = operation.Message; if (string.IsNullOrEmpty(message)) { return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty)); } receiver.ReceiveTell(this, message); } break; default: { #if MMO_DEBUG _logger.DebugFormat("[HandleOperationSendChat]: Session (Name={0}) sent an unhandled Message (Type={1})", name, (MessageType)operation.MessageType); #endif } break; } return(null); } /// <summary> /// Call this to handle client operation requests /// </summary> void OnOperationRequest(GameOperationRequest operationRequest, MessageParameters messageParameters) { GameOperationResponse response; switch ((GameOperationCode)operationRequest.OperationCode) { case GameOperationCode.SendChat: response = this.HandleOperationSendChat(operationRequest); break; default: response = new GameErrorResponse(operationRequest.OperationCode) { ReturnCode = (short)ResultCode.OperationNotAvailable }; break; } if (response != null) { this.SendOperationResponse(response, messageParameters); } } #endregion #region Helper Methods void DoAddSession() { // adding session to the chat while (!chat.AddSession(this)) { ChatSession exisitingSession; if (chat.SessionCache.TryGetSessionBySessionId(sessionId, out exisitingSession)) { // this shouldn't happen because the master won't let the same player login twice it will disconnect the exisitng player // we are handling it to satisfy Murphy's Law #if MMO_DEBUG _logger.DebugFormat("[DoAddSession]: ChatSession (Name={0}) cannot be added because an existing ChatSession (Name={1}) is found", this.Name, exisitingSession.Name); #endif exisitingSession.Disconnect(); this.Disconnect(); this.Destroy(DestroySessionReason.KickedByExistingSession); return; } } } #endregion }