Esempio n. 1
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        private static GameServer CreateServer()
        {
            if (!File.Exists(ServerConfig.SERVER_CONFIG_FILE))
            {
                IniWriter writer = new IniWriter(ServerConfig.SERVER_CONFIG_FILE);

                writer.addAndSelectSection(ServerConfig.SECTION_GENERAL);

                writer.addKeyToSelectedSection(ServerConfig.GENERAL_KEY_GAME, "Skyrim", "Game to set: Skyrim, Oblivion");
                writer.addKeyToSelectedSection(ServerConfig.GENERAL_KEY_NAME, "Server Name", "Your server name");
                writer.addKeyToSelectedSection(ServerConfig.GENERAL_KEY_ADDRESS, "127.0.0.1", "Local ip address or name");
                writer.addKeyToSelectedSection(ServerConfig.GENERAL_KEY_PORT, "14242", "Server port default: 14242");
                writer.addKeyToSelectedSection(ServerConfig.GENERAL_KEY_ONLINE, "true",
                    "Server online flag to enable inbound internet connection default: true");
                writer.addKeyToSelectedSection(ServerConfig.GENERAL_KEY_LANGUAGE, "English",
                    "Server language communications, defaulat: English");
                writer.addKeyToSelectedSection(ServerConfig.GENERAL_KEY_PASSWORD, "",
                    "If password is set game will be private only for players with password, defaulat: \"\" ");

                writer.addAndSelectSection(ServerConfig.SECTION_MASTER);

                writer.addKeyToSelectedSection(ServerConfig.MASTER_KEY_GUID, "",
                    "Server GUID, to generate use http://www.guidgenerator.com/, default: \"\" ");

                if (!writer.SaveFile())
                {
                    Console.WriteLine("ERROR: Server config ini file not created");
                }
            }

            config =
                new ServerConfig(
                    iniLoader.GetValue(ServerConfig.SECTION_GENERAL, ServerConfig.GENERAL_KEY_GAME, "Skyrim"),
                    iniLoader.GetValue(ServerConfig.SECTION_GENERAL, ServerConfig.GENERAL_KEY_NAME, "Server Name"),
                    iniLoader.GetValue(ServerConfig.SECTION_GENERAL, ServerConfig.GENERAL_KEY_ADDRESS, "127.0.0.1"),
                    iniLoader.GetValue(ServerConfig.SECTION_GENERAL, ServerConfig.GENERAL_KEY_PORT, 14242),
                    iniLoader.GetValue(ServerConfig.SECTION_GENERAL, ServerConfig.GENERAL_KEY_ONLINE, true),
                    iniLoader.GetValue(ServerConfig.SECTION_GENERAL, ServerConfig.GENERAL_KEY_LANGUAGE, "English"),
                    iniLoader.GetValue(ServerConfig.SECTION_GENERAL, ServerConfig.GENERAL_KEY_PASSWORD, ""),
                    iniLoader.GetValue(ServerConfig.SECTION_MASTER, ServerConfig.MASTER_KEY_GUID, "")
                    );

            return new GameServer(config);
        }
Esempio n. 2
0
        public GameServer(ServerConfig sConfig)
        {
            serverConfig = sConfig;

            Name = serverConfig.getServerName();
            Port = serverConfig.getServerPort();
            world = new GameWorld(this);

            NetPeerConfiguration npConfig = new NetPeerConfiguration("game");
            npConfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            npConfig.EnableMessageType(NetIncomingMessageType.StatusChanged);
            npConfig.EnableMessageType(NetIncomingMessageType.Data);
            npConfig.Port = Port;

            server = new NetServer(npConfig);
            server.Start();

            Initialize();

            Logger.InfoFormat("Started {0} on port {1} !", Name, Port);
        }