Beispiel #1
0
        public static User GetUser(string name, string uuid, string ip)
        {
            if (File.Exists(Path.Combine(UsersPath, name.ToLower() + ".json")))
            {
                try
                {
                    User user = Read(Path.Combine(UsersPath, name.ToLower() + ".json"), new string[] { name, uuid });
                    return(user);
                }
                catch (Exception)
                {
                    StarryboundServer.logError("Player data for user " + name.ToLower() + " with UUID " + uuid + " is corrupt. Re-generating user file");

                    User user = new User(name, uuid, ip, StarryboundServer.defaultGroup, false, true, 0, true, true, false, new List <string>(), new List <string>());
                    Write(Path.Combine(UsersPath, name.ToLower() + ".json"), user);

                    return(user);
                }
            }
            else
            {
                User user = new User(name, uuid, ip, StarryboundServer.defaultGroup, false, true, 0, false, false, false, new List <string>(), new List <string>());
                Write(Path.Combine(UsersPath, name.ToLower() + ".json"), user);

                return(user);
            }
        }
        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);
        }