public override object onReceive()
        {
            BinaryReader packetData = (BinaryReader)this.stream;

            bool   success      = packetData.ReadBoolean();
            uint   clientID     = packetData.ReadVarUInt32();
            string rejectReason = packetData.ReadStarString();

            Client target = StarryboundServer.getClient(clientID);

            if (target != null)
            {
                target.forceDisconnect(direction, "The parent server reclaimed this clientId");
                StarryboundServer.logError("[" + this.client.playerData.name + "] " + direction + ": The parent server reclaimed this clientId (" + clientID + ")");
                return(true);
            }

            this.client.playerData.id = clientID;
            PlayerData player = this.client.playerData;

            if (!success)
            {
                this.client.rejectPreConnected("Connection Failed: Rejected by parent server: " + rejectReason);
                return(true);
            }

            StarryboundServer.addClient(this.client);

            string geoip_prefix = "";

            if (StarryboundServer.config.enableGeoIP && StarryboundServer.Geo != null)
            {
                var code    = StarryboundServer.Geo.TryGetCountryCode(IPAddress.Parse(player.ip));
                var geo_loc = code == null ? "N/A" : GeoIPCountry.GetCountryNameByCode(code);
                geoip_prefix = String.Format("({0})", geo_loc);
            }

            StarryboundServer.sendGlobalMessage(String.Format("{0}{1} has joined the server!", player.name, geoip_prefix));
            this.client.state = ClientState.Connected;
            StarryboundServer.logInfo(String.Format("[{0}][{1}] joined with UUID [{2}]{3}", this.client.playerData.client, this.client.playerData.ip, player.uuid,
                                                    geoip_prefix != "" ? String.Format(" from {0}", geoip_prefix) : ""));

            return(true);
        }
Exemple #2
0
        private void OnServerConnect(ConnectEventArgs args)
        {
            if (TShock.ShuttingDown)
            {
                NetMessage.SendData(2, args.Who, -1, NetworkText.FromLiteral("Server is shutting down..."));
                args.Handled = true;
                return;
            }

            var player = new TSPlayer(args.Who);

            Utils.CacheIP?.SetValue(player, _forward[args.Who].IP);
            if (TShock.Utils.ActivePlayers() + 1 > TShock.Config.MaxSlots + TShock.Config.ReservedSlots)
            {
                player.Disconnect(TShock.Config.ServerFullNoReservedReason);
                args.Handled = true;
                return;
            }

            if (!FileTools.OnWhitelist(player.IP))
            {
                player.Disconnect(TShock.Config.WhitelistKickReason);
                args.Handled = true;
                return;
            }

            if (TShock.Geo != null)
            {
                var code = TShock.Geo.TryGetCountryCode(IPAddress.Parse(player.IP));
                player.Country = code == null ? "N/A" : GeoIPCountry.GetCountryNameByCode(code);
                if (code == "A1" && TShock.Config.KickProxyUsers)
                {
                    player.Disconnect("Proxies are not allowed.");
                    args.Handled = true;
                    return;
                }
            }

            TShock.Players[args.Who] = player;
        }
Exemple #3
0
        /// <summary>
        /// Handles ip information on a new client
        /// </summary>
        /// <param name="remoteAddress">The IP address of the user</param>
        /// <param name="player">The player bound to the client with this IP</param>
        /// <returns>Whether or not the update was made successfully</returns>
        private bool HandleIpInformation(string remoteAddress, TSPlayer player)
        {
            typeof(TSPlayer).GetField("CacheIP", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
            .SetValue(player, remoteAddress);

            // This needs to be handled as Geo check for proxy in TShock runs before the IP is updated to the correct one
            if (Dimensions.Geo != null)
            {
                var code = Dimensions.Geo.TryGetCountryCode(System.Net.IPAddress.Parse(remoteAddress));
                player.Country = code == null ? "N/A" : GeoIPCountry.GetCountryNameByCode(code);
                if (code == "A1")
                {
                    if (TShock.Config.KickProxyUsers)
                    {
                        TShock.Utils.ForceKick(player, "Proxies are not allowed.", true, true);
                        return(false);
                    }
                }
            }

            return(true);
        }