Exemplo n.º 1
0
        private static void HandleMessage(IMasterServerMessageBase message, NetIncomingMessage netMsg, NetPeer peer)
        {
            switch ((message?.Data as MsBaseMsgData)?.MasterServerMessageSubType)
            {
            case MasterServerMessageSubType.REGISTER_SERVER:
                RegisterServer(message, netMsg);
                break;

            case MasterServerMessageSubType.REQUEST_SERVERS:
                var version = ((MsRequestServersMsgData)message.Data).CurrentVersion;
                Form.WriteLine($"Received LIST REQUEST from: {netMsg.SenderEndPoint} version: {version}");
                SendServerLists(netMsg, peer, version);
                break;

            case MasterServerMessageSubType.INTRODUCTION:
                Form.WriteLine("Received INTRODUCTION request from:" + netMsg.SenderEndPoint);
                var    msgData = (MsIntroductionMsgData)message.Data;
                Server server;
                if (ServerDictionary.TryGetValue(msgData.Id, out server))
                {
                    peer.Introduce(
                        server.InternalEndpoint,
                        server.ExternalEndpoint,
                        Common.CreateEndpointFromString(msgData.InternalEndpoint), // client internal
                        netMsg.SenderEndPoint,                                     // client external
                        msgData.Token);                                            // request token
                }
                else
                {
                    Form.WriteLine("Client requested introduction to nonlisted host!");
                }
                break;
            }
        }
Exemplo n.º 2
0
        private static void HandleMessage(IMasterServerMessageBase message, NetIncomingMessage netMsg, NetPeer peer)
        {
            if (BannedIpsRetriever.IsBanned(netMsg.SenderEndPoint))
            {
                LunaLog.Debug($"Ignoring BANNED ip: {netMsg.SenderEndPoint}");
                return;
            }

            try
            {
                switch ((message?.Data as MsBaseMsgData)?.MasterServerMessageSubType)
                {
                case MasterServerMessageSubType.RegisterServer:
                    RegisterServer(message, netMsg);
                    break;

                case MasterServerMessageSubType.RequestServers:
                    LunaLog.Normal($"LIST REQUEST from: {netMsg.SenderEndPoint}");
                    SendServerLists(netMsg, peer);
                    break;

                case MasterServerMessageSubType.Introduction:
                    var msgData = (MsIntroductionMsgData)message.Data;
                    if (ServerDictionary.TryGetValue(msgData.Id, out var server))
                    {
                        LunaLog.Normal($"INTRODUCTION request from: {netMsg.SenderEndPoint} to server: {server.ExternalEndpoint}");
                        peer.Introduce(server.InternalEndpoint, server.ExternalEndpoint,
                                       msgData.InternalEndpoint, // client internal
                                       netMsg.SenderEndPoint,    // client external
                                       msgData.Token);           // request token
                    }
                    else
                    {
                        LunaLog.Warning($"Client {netMsg.SenderEndPoint} requested introduction to non listed host!");
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                LunaLog.Error($"Error handling message. Details: {e}");
            }
        }
Exemplo n.º 3
0
        private static void HandleMessage(IMasterServerMessageBase message, NetIncomingMessage netMsg, NetPeer peer)
        {
            try
            {
                switch ((message?.Data as MsBaseMsgData)?.MasterServerMessageSubType)
                {
                case MasterServerMessageSubType.RegisterServer:
                    RegisterServer(message, netMsg);
                    break;

                case MasterServerMessageSubType.RequestServers:
                    ConsoleLogger.Log(LogLevels.Normal, $"LIST REQUEST from: {netMsg.SenderEndPoint}");
                    SendServerLists(netMsg, peer);
                    break;

                case MasterServerMessageSubType.Introduction:
                    var msgData = (MsIntroductionMsgData)message.Data;
                    if (ServerDictionary.TryGetValue(msgData.Id, out var server))
                    {
                        ConsoleLogger.Log(LogLevels.Normal, $"INTRODUCTION request from: {netMsg.SenderEndPoint} to server: {server.ExternalEndpoint}");
                        peer.Introduce(server.InternalEndpoint, server.ExternalEndpoint,
                                       Common.CreateEndpointFromString(msgData.InternalEndpoint), // client internal
                                       netMsg.SenderEndPoint,                                     // client external
                                       msgData.Token);                                            // request token
                    }
                    else
                    {
                        ConsoleLogger.Log(LogLevels.Warning, $"Client {netMsg.SenderEndPoint} requested introduction to nonlisted host!");
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                ConsoleLogger.Log(LogLevels.Error, $"Error handling message. Details: {e}");
            }
        }
Exemplo n.º 4
0
        private static void HandleMessage(IMasterServerMessageBase message, NetIncomingMessage netMsg, NetPeer peer)
        {
            if (BannedIpsRetriever.IsBanned(netMsg.SenderEndPoint))
            {
                LunaLog.Debug($"Ignoring BANNED ip: {netMsg.SenderEndPoint}");
                return;
            }

            try
            {
                switch ((message?.Data as MsBaseMsgData)?.MasterServerMessageSubType)
                {
                case MasterServerMessageSubType.RegisterServer:
                    RegisterServer(message, netMsg);
                    break;

                case MasterServerMessageSubType.RequestServers:
                    LunaLog.Normal($"LIST REQUEST from: {netMsg.SenderEndPoint}");
                    SendServerLists(netMsg, peer);
                    break;

                case MasterServerMessageSubType.Introduction:
                    var msgData = (MsIntroductionMsgData)message.Data;
                    if (ServerDictionary.TryGetValue(msgData.Id, out var server))
                    {
                        _ = Task.Run(() =>
                        {
                            if (!server.InternalEndpoint6.Address.Equals(IPAddress.IPv6Loopback) &&
                                !server.InternalEndpoint6.Address.Equals(IPAddress.IPv6Loopback))
                            {
                                // Both client and server are listening on IPv6, try an IPv6 firewall punchthrough
                                // This also triggers a first punchthrough on IPv4 with the public addresses
                                LunaLog.Normal(
                                    $"INTRODUCTION request from: {msgData.InternalEndpoint6} to server: {server.InternalEndpoint6}");
                                peer.Introduce(server.InternalEndpoint6, server.ExternalEndpoint,
                                               msgData.InternalEndpoint6, // client internal
                                               netMsg.SenderEndPoint,     // client external
                                               msgData.Token);            // request token

                                // Give the first introduction attempt some time
                                Thread.Sleep(50);
                            }

                            LunaLog.Normal(
                                $"INTRODUCTION request from: {netMsg.SenderEndPoint} to server: {server.ExternalEndpoint}");
                            peer.Introduce(server.InternalEndpoint, server.ExternalEndpoint,
                                           msgData.InternalEndpoint, // client internal
                                           netMsg.SenderEndPoint,    // client external
                                           msgData.Token);           // request token
                        });
                    }
                    else
                    {
                        LunaLog.Warning($"Client {netMsg.SenderEndPoint} requested introduction to non listed host!");
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                LunaLog.Error($"Error handling message. Details: {e}");
            }
        }