Пример #1
0
        public void SendChatMessage(string message)
        {
            //Array.ConvertAll(new char[16], v => (char) 99).ToString()
            var ack = new ChatMessageAnswer
            {
                MessageType         = "channel",
                SenderCharacterName = "SERVER",
                Message             = message
            };

            Send(ack.CreatePacket());
        }
Пример #2
0
        private static CommandResult NoticeCommandHandler(DefaultServer server, Client sender, string command,
                                                          IList <string> args)
        {
            // Doesn't work right. Sending /notice notice does work. But "prints out notice XYZ" to chat..
            if (args.Count == 0)
            {
                return(CommandResult.InvalidArgument);
            }

            var msg = string.Join(" ", args);
            var ack = new ChatMessageAnswer()
            {
                MessageType         = "channel",
                SenderCharacterName = "GM",
                Message             = msg,
            }.CreatePacket();

            server.Broadcast(ack);

            return(CommandResult.Okay);
        }
Пример #3
0
        public static void Handle(Packet packet)
        {
            var chatMsgPacket = new ChatMessagePacket(packet);

            var sender = packet.Sender.User.ActiveCharacter.Name;

            if (packet.Sender.User.GmFlag)
            {
                sender = $"GM {sender}";
            }

            if (packet.Sender.User.Status == UserStatus.Muted)
            {
                packet.Sender.SendError("You are currently blocked from chatting.");
                return;
            }

            Log.Debug($"({chatMsgPacket.MessageType}) <{sender}> {chatMsgPacket.Message}");

            var ack = new ChatMessageAnswer
            {
                MessageType         = chatMsgPacket.MessageType,
                SenderCharacterName = sender,
                Message             = chatMsgPacket.Message
            };

            var ackPkt = ack.CreatePacket();

            switch (chatMsgPacket.MessageType)
            {
            case "room":
                GameServer.Instance.Server.BroadcastArea(0, ackPkt);
                break;

            case "channel":
                if (packet.Sender?.User?.ActiveCharacter != null)
                {
                    GameServer.Instance.Server.BroadcastChannel(packet.Sender.User.ActiveCharacter.LastChannel, ackPkt);
                }
                break;

            case "party":
                if (packet.Sender.User.ActiveCharacter.PartyType == 65)
                {
                    GameServer.Instance.Server.Broadcast(ackPkt);     // TODO: broadcast only to users in same party
                }
                else
                {
                    packet.Sender.SendError("You haven't joined any group.");
                }
                break;

            case "team":
                if (packet.Sender.User.ActiveCharacter.Crew != null)
                {
                    GameServer.Instance.Server.Broadcast(packet.Sender.User.ActiveCharacter.Crew, ackPkt);
                }
                else
                {
                    packet.Sender.SendError("Not a member of a crew.");
                }
                break;

            default:
                packet.Sender.SendError("Cannot find the chat window.");
                Log.Error("Undefined chat message type.");
                break;
            }
        }