Beispiel #1
0
 static User Read(string path, string[] data)
 {
     using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         User file = Read(fs, data);
         StarryboundServer.logInfo("Loaded persistant user storage for " + file.name);
         return(file);
     }
 }
Beispiel #2
0
        public static List <Group> Read(string path)
        {
            if (!File.Exists(path))
            {
                return(DefaultGroups());
            }

            using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                List <Group> file = Read(fs);
                StarryboundServer.logInfo("Starrybound groups loaded successfully.");
                return(file);
            }
        }
        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);
        }
Beispiel #4
0
        public static void ProcessGroups(List <Group> groupList)
        {
            try
            {
                string defaultGroup = null;

                foreach (Group group in groupList)
                {
                    StarryboundServer.groups.Add(group.name, group);
                    if (group.isDefault)
                    {
                        defaultGroup = group.name;
                    }
                }

                if (String.IsNullOrWhiteSpace(defaultGroup))
                {
                    StarryboundServer.logFatal("Default user group flag (isDefault) is not set for any groups - Please set this in the groups.json!");
                    Thread.Sleep(5000);
                    Environment.Exit(5);
                }

                foreach (Group groupCheck in StarryboundServer.groups.Values)
                {
                    if (!String.IsNullOrWhiteSpace(groupCheck.parent))
                    {
                        if (!StarryboundServer.groups.ContainsKey(groupCheck.parent))
                        {
                            throw new RankException("Parent (" + groupCheck.parent + ") for group " + groupCheck.name + " does not exist!");
                        }
                    }
                }

                StarryboundServer.defaultGroup = defaultGroup;

                StarryboundServer.logInfo("Loaded " + StarryboundServer.groups.Count + " group(s). Default group is " + defaultGroup);
            }
            catch (RankException e)
            {
                StarryboundServer.logFatal("A fatal exception occurred while processing the groups (Groups::ProcessGroups): " + e.ToString());
                Thread.Sleep(5000);
                Environment.Exit(5);
            }
        }
Beispiel #5
0
        public static string ReloadGroups()
        {
            try
            {
                Dictionary <string, Group> tmpDict = new Dictionary <string, Group>();

                List <Group> groupList    = GroupFile.Read(GroupsPath);
                string       defaultGroup = null;

                foreach (Group group in groupList)
                {
                    tmpDict.Add(group.name, group);
                    if (group.isDefault)
                    {
                        defaultGroup = group.name;
                    }
                }

                if (String.IsNullOrWhiteSpace(defaultGroup))
                {
                    StarryboundServer.logFatal("Default user group flag (isDefault) is not set for any groups - Please set this in the groups.json!");
                    return("isDefault flag is not set for any group!");
                }

                var buffer = StarryboundServer.getClients();
                foreach (Client client in buffer)
                {
                    if (!tmpDict.ContainsKey(client.playerData.group.name))
                    {
                        StarryboundServer.logInfo("Updating user " + client.playerData.name + " to default group (" + defaultGroup + ") as old group " + client.playerData.group.name + " has been deleted.");
                        client.playerData.group = tmpDict[defaultGroup];
                    }
                }

                StarryboundServer.defaultGroup = defaultGroup;
                StarryboundServer.groups       = tmpDict;

                StarryboundServer.logInfo("Loaded " + StarryboundServer.groups.Count + " group(s). Default group is " + defaultGroup);
                return(null);
            }
            catch (Exception) { return("Command handler threw an exception!"); }
        }
        /// <summary>
        /// Reads the data from the packet stream
        /// </summary>
        /// <returns>true to maintain packet and send to client, false to drop packet, -1 will boot the client</returns>
        public override Object onReceive()
        {
            BinaryReader packetData = (BinaryReader)this.stream;

            string message = packetData.ReadStarString();
            byte   context = packetData.ReadByte();

            #region Command Processor
            if (message.StartsWith("#"))
            {
                StarryboundServer.logInfo("[Admin Chat] [" + this.client.playerData.name + "]: " + message);

                bool aChat = new AdminChat(this.client).doProcess(new string[] { message.Remove(0, 1) });

                return(false);
            }
            else if (message.StartsWith("/"))
            {
                try
                {
                    StarryboundServer.logInfo("[Command] [" + this.client.playerData.name + "]: " + message);
                    string[] args = message.Remove(0, 1).Split(' ');
                    string   cmd  = args[0].ToLower();

                    args = parseArgs(message.Remove(0, cmd.Length + 1));

                    switch (cmd)
                    {
                    case "ban":
                        new BanC(this.client).doProcess(args);
                        break;

                    case "unban":
                        new UnbanCommand(this.client).doProcess(args);
                        break;

                    case "reload":
                        new Reload(this.client).doProcess(args);
                        break;

                    case "kick":
                        new Kick(this.client).doProcess(args);
                        break;

                    case "fuel":
                        new Fuel(this.client).doProcess(args);
                        break;

                    case "starteritems":
                        new StarterItems(this.client).doProcess(args);
                        break;

                    case "admin":
                        new AdminChat(this.client).doProcess(args);
                        break;

                    case "rules":
                        new Rules(this.client).doProcess(args);
                        break;

                    case "version":
                        new VersionC(this.client).doProcess(args);
                        break;

                    case "me":
                        new Me(this.client).doProcess(args);
                        break;

                    case "pvp":
                    case "w":
                        return(true);

                    case "nick":
                        if (this.client.playerData.hasPermission("cmd.nick"))
                        {
                            return(true);
                        }
                        else
                        {
                            this.client.sendChatMessage(ChatReceiveContext.Whisper, "", "You do not have permission to use this command.");
                        }
                        break;

                    case "who":
                    case "online":
                    case "players":
                        new List(this.client).doProcess(args);
                        break;

                    case "whosthere":
                        new WhosThere(this.client).doProcess(args);
                        break;

                    case "broadcast":
                        new Broadcast(this.client).doProcess(args);
                        break;

                    case "ship":
                        new Ship(this.client).doProcess(args);
                        break;

                    case "planet":
                        new Planet(this.client).doProcess(args);
                        break;

                    case "home":
                        new Home(this.client).doProcess(args);
                        break;

                    case "item":
                    case "give":
                        new Item(this.client).doProcess(args);
                        break;

                    case "mute":
                        new Mute(this.client).doProcess(args);
                        break;

                    case "uptime":
                        new Uptime(this.client).doProcess(args);
                        break;

                    case "shutdown":
                        new Shutdown(this.client).doProcess(args);
                        break;

                    case "restart":
                        new Restart(this.client).doProcess(args);
                        break;

                    case "build":
                        new Build(this.client).doProcess(args);
                        break;

                    case "where":
                    case "find":
                        new Find(this.client).doProcess(args);
                        break;

                    case "warpship":
                        new WarpShip(this.client).doProcess(args);
                        break;

                    case "spawn":
                        new Spawn(this.client).doProcess(args);
                        break;

                    case "group":
                        new GroupC(this.client).doProcess(args);
                        break;

                    /*
                     * case "sethome":
                     * new SetHome(this.client).doProcess(args);
                     * break;
                     */

                    case "shipaccess":
                        new ShipAccess(this.client).doProcess(args);
                        break;

                    case "help":
                    case "commands":
                    case "commandlist":
                    case "?":
                        new Help(this.client).doProcess(args);
                        break;

                    case "auth":
                        if (String.IsNullOrWhiteSpace(StarryboundServer.authCode))
                        {
                            goto default;
                        }
                        else
                        {
                            new Auth(this.client).doProcess(args);
                        }
                        break;

                    case "claim":
                        new Claim(this.client).doProcess(args);
                        break;

                    default:
                        this.client.sendCommandMessage("Command " + cmd + " not found.");
                        break;
                    }
                    return(false);
                }
                catch (Exception e)
                {
                    this.client.sendCommandMessage("Command failed: " + e.Message);
                    Console.WriteLine(e.ToString());
                }
            }
            #endregion

            if (this.client.playerData.isMuted)
            {
                this.client.sendCommandMessage("^#f75d5d;You try to speak, but nothing comes out... You have been muted.");
                return(false);
            }

            StarryboundServer.logInfo("[" + ((ChatSendContext)context).ToString() + "] [" + this.client.playerData.name + "]: " + message);
            return(true);
        }