Esempio n. 1
0
    string ParseMessage(ServerGameLoop.ClientInfo from, string message, out ChatMessageType type, out ServerGameLoop.ClientInfo target)
    {
        type   = ChatMessageType.All;
        target = null;

        var match = m_CommandRegex.Match(message);

        if (match.Success)
        {
            var command       = match.Groups[1].Value.ToLower();
            var actualMessage = match.Groups[2].Value;
            switch (command)
            {
            case "t":
            case "team":
                type = ChatMessageType.Team;
                return(match.Groups[2].Value);

            case "w":
            case "whisper":
                var match2 = m_TargetRegex.Match(actualMessage);
                if (match2.Success)
                {
                    type = ChatMessageType.Whisper;

                    // try to find client
                    var name = !String.IsNullOrEmpty(match2.Groups[1].Value) ? match2.Groups[1].Value : match2.Groups[2].Value;
                    foreach (var pair in m_Clients)
                    {
                        if (pair.Value.playerSettings.playerName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            target = pair.Value;
                            m_ReplyTracker[target] = from;
                            return(match2.Groups[3].Value);
                        }
                    }
                }
                return(actualMessage);

            case "r":
            case "reply":
                if (m_ReplyTracker.TryGetValue(from, out target))
                {
                    type = ChatMessageType.Whisper;
                    m_ReplyTracker[target] = from;
                }
                return(actualMessage);

            case "a":
            case "all":
            default:
                return(actualMessage);
            }
        }
        return(message);
    }
Esempio n. 2
0
 public bool HandleClientCommand(ServerGameLoop.ClientInfo client, string v)
 {
     if (v == "nextchar")
     {
         GameDebug.Log("nextchar for client " + client.id);
         m_GameModeSystem.RequestNextChar(client.player);
     }
     else
     {
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
    public void ReceiveMessage(ServerGameLoop.ClientInfo from, string message)
    {
        ChatMessageType type;

        ServerGameLoop.ClientInfo target;

        var time    = (Game.Clock.ElapsedMilliseconds - m_StartTime) / 1000;
        var minutes = time / 60;
        var seconds = time % 60;

        var text = ParseMessage(from, message, out type, out target);

        if (type == ChatMessageType.Whisper)
        {
            if (target != null)
            {
                var fromLine = string.Format("<color=#ffffffff>[{0}:{1:00}]</color><color=#ff00ffff> [From {2}] {3}</color>", minutes, seconds, from.playerSettings.playerName, text);
                SendChatMessage(target.id, fromLine);

                var toLine = string.Format("<color=#ffffffff>[{0}:{1:00}]</color><color=#ff00ffff> [To {2}] {3}</color>", minutes, seconds, target.playerSettings.playerName, text);
                SendChatMessage(from.id, toLine);
            }
            else
            {
                SendChatMessage(from.id, string.Format("<color=#ff0000ff> Player not found</color>"));
            }
        }
        else if (type == ChatMessageType.All || type == ChatMessageType.Team)
        {
            var marker = type == ChatMessageType.All ? "[All] " : "";

            var friendly = string.Format("[{0}:{1:00}] <color=#1D89CC>{2}{3}</color> {4}", minutes, seconds, marker, from.playerSettings.playerName, text);
            var hostile  = string.Format("[{0}:{1:00}] <color=#FF3E3E>{2}{3}</color> {4}", minutes, seconds, marker, from.playerSettings.playerName, text);

            var fromTeamIndex = from.player != null ? from.player.teamIndex : -1;
            foreach (var pair in m_Clients)
            {
                var targetTeamIndex = pair.Value.player != null ? pair.Value.player.teamIndex : -1;
                if (fromTeamIndex == targetTeamIndex)
                {
                    SendChatMessage(pair.Key, friendly);
                }
                else if (type == ChatMessageType.All)
                {
                    SendChatMessage(pair.Key, hostile);
                }
            }
        }
    }
Esempio n. 4
0
 public void HandleClientDisconnect(ServerGameLoop.ClientInfo client)
 {
     m_PlayerModule.CleanupPlayer(client.player);
     m_CharacterModule.CleanupPlayer(client.player);
 }
Esempio n. 5
0
 public void HandleClientConnect(ServerGameLoop.ClientInfo client)
 {
     client.player = m_PlayerModule.CreatePlayer(m_GameWorld, client.id, "", client.isReady);
 }