Esempio n. 1
0
        public Tuple<bool, string> InitAndStartNetwork(ServerNetworkConfig netConfig, ServerAppConfig appConfig)
        {
            AppConfig = appConfig;
            NetConfig = new NetworkConfig()
            {
                IP = netConfig.IP,
                Port = netConfig.Port,
                EngineDllName = netConfig.EngineDllName,
                MaxAcceptCount = netConfig.MaxAcceptCount,
                ThreadCount = netConfig.ThreadCount,
                ProtocolOption = 0,
                ProtocolID = 0,
                MaxBufferSize = netConfig.MaxBufferSize,
                MaxPacketSize = netConfig.MaxPacketSize,
            };

            var result = ServerNet.Init(NetConfig, null, null);
            if (result != NET_ERROR_CODE_N.SUCCESS)
            {
                return new Tuple<bool, string>(false,result.ToString());
            }

            if (ServerNet.Start(NetConfig.ProtocolID) == false)
            {
                return new Tuple<bool, string>(false, NET_ERROR_CODE_N.NETWORK_START_FAIL.ToString());
            }
            else
            {
                IsStartServerNetwork = true;
            }

            return new Tuple<bool, string>(true, NET_ERROR_CODE_N.SUCCESS.ToString());
        }
Esempio n. 2
0
        public ERROR_CODE CreateSystem(ServerAppConfig appConfig)
        {
            if (appConfig.ProcessThreadCount < 2)
            {
                return ERROR_CODE.LESS_PACKET_PROCESS_THREAD_COUNT;
            }

            var lobbyProcessThreadCount = appConfig.ProcessThreadCount - 1;
            if ((appConfig.MaxLobbyCount % lobbyProcessThreadCount) != 0)
            {
                return ERROR_CODE.INVALID_LOBBY_COUNT_PER_WORK_PACKET_PROCESS;
            }

            var lobbyCountPerWorkPacketProcess = appConfig.MaxLobbyCount / lobbyProcessThreadCount;

            var result = DBManager.CreateAndStart(1, DBResponseFunc);
            if (result != ERROR_CODE.NONE)
            {
                return result;
            }

            CreateAndStartPacketSysytem(appConfig, lobbyProcessThreadCount, lobbyCountPerWorkPacketProcess);

            return ERROR_CODE.NONE;
        }
        public void Init(ServerAppConfig appConfig, ServerNetwork serverNetwork, DB.DBManager dbManager)
        {
            ServerNetworkRef = serverNetwork;
            DBManagerRef = dbManager;

            UserManagerInst = new ConnectUserManager();
            UserManagerInst.Init(appConfig.MaxTotalUserCount);

            RegistPacketHandler();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            workProcessTimer.Tick    += new EventHandler(OnProcessTimedEvent);
            workProcessTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
            workProcessTimer.Start();


            var netConfig = new ChatServerLib.ServerNetworkConfig()
            {
                IP             = "127.0.0.1",
                Port           = textBoxPort.Text.ToUInt16(),
                EngineDllName  = "CGSFNet.dll",
                MaxAcceptCount = textBoxMaxUserCount.Text.ToInt32(),
                ThreadCount    = textBoxPacketThreadCount.Text.ToInt32(),
                MaxBufferSize  = textBoxMaxBufferSize.Text.ToInt32(),
                MaxPacketSize  = textBoxMaxPacketSize.Text.ToInt32(),
            };

            var appConfig = new ChatServerLib.ServerAppConfig()
            {
                MaxTotalUserCount  = textBoxMaxUserCount.Text.ToInt32(),
                MaxLobbyCount      = textBoxLobbyCount.Text.ToInt32(),
                MaxLobbyUserCount  = textBoxMaxUserPerLobby.Text.ToInt32(),
                ProcessThreadCount = textBoxPacketThreadCount.Text.ToInt32(),
                DBThreadCount      = textBoxDBThreadCount.Text.ToInt32(),
            };


            var result = ServerLib.InitAndStartNetwork(netConfig, appConfig);

            if (result.Item1 == false)
            {
                DevLog.Write(string.Format("[Init] 네트워크 라이브러리 초기화 및 시작 실패. {0}", result.Item2.ToString()), LOG_LEVEL.ERROR);
                return;
            }

            DevLog.Write(string.Format("[Start] 네트워크 시작"), LOG_LEVEL.INFO);


            var errorCode = ServerLib.CreateSystem(appConfig);

            if (errorCode != CSCommonLib.ERROR_CODE.NONE)
            {
                DevLog.Write(string.Format("[Init] CreateSystem 실패. {0}", errorCode), LOG_LEVEL.ERROR);
                return;
            }

            DevLog.Write(string.Format("[Start] CreateSystem 완료"), LOG_LEVEL.INFO);
        }
Esempio n. 5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            workProcessTimer.Tick += new EventHandler(OnProcessTimedEvent);
            workProcessTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
            workProcessTimer.Start();

            var netConfig = new ChatServerLib.ServerNetworkConfig()
            {
                IP = "127.0.0.1",
                Port = textBoxPort.Text.ToUInt16(),
                EngineDllName = "CGSFNet.dll",
                MaxAcceptCount = textBoxMaxUserCount.Text.ToInt32(),
                ThreadCount = textBoxPacketThreadCount.Text.ToInt32(),
                MaxBufferSize = textBoxMaxBufferSize.Text.ToInt32(),
                MaxPacketSize = textBoxMaxPacketSize.Text.ToInt32(),
            };

            var appConfig = new ChatServerLib.ServerAppConfig()
            {
                MaxTotalUserCount = textBoxMaxUserCount.Text.ToInt32(),
                MaxLobbyCount = textBoxLobbyCount.Text.ToInt32(),
                MaxLobbyUserCount = textBoxMaxUserPerLobby.Text.ToInt32(),
                ProcessThreadCount = textBoxPacketThreadCount.Text.ToInt32(),
                DBThreadCount = textBoxDBThreadCount.Text.ToInt32(),
            };

            var result = ServerLib.InitAndStartNetwork(netConfig, appConfig);
            if (result.Item1 == false)
            {
                DevLog.Write(string.Format("[Init] 네트워크 라이브러리 초기화 및 시작 실패. {0}", result.Item2.ToString()), LOG_LEVEL.ERROR);
                return;
            }

            DevLog.Write(string.Format("[Start] 네트워크 시작"), LOG_LEVEL.INFO);

            var errorCode = ServerLib.CreateSystem(appConfig);
            if (errorCode != CSCommonLib.ERROR_CODE.NONE)
            {
                DevLog.Write(string.Format("[Init] CreateSystem 실패. {0}", errorCode), LOG_LEVEL.ERROR);
                return;
            }

            DevLog.Write(string.Format("[Start] CreateSystem 완료"), LOG_LEVEL.INFO);
        }
        public void Init(int index, int lobbyCountPerWorkPacketProcess, ServerAppConfig appConfig, ServerNetwork serverNetwork, DB.DBManager dbManager)
        {
            Index = index;
            ServerNetworkRef = serverNetwork;
            DBManagerRef = dbManager;

            var firstLobbyID = ((Index - 1) * lobbyCountPerWorkPacketProcess) + 1;
            if (Index != 1)
            {
                firstLobbyID = Index * lobbyCountPerWorkPacketProcess;
            }

            LobbyManagerInst = new Lobby.LobbyManager();
            LobbyManagerInst.Init(firstLobbyID, lobbyCountPerWorkPacketProcess, appConfig, serverNetwork);

            RegistPacketHandler();

            IsThreadRunning = true;
            ProcessThread = new System.Threading.Thread(this.Process);
            ProcessThread.Start();
        }
Esempio n. 7
0
        public Tuple <bool, string> InitAndStartNetwork(ServerNetworkConfig netConfig, ServerAppConfig appConfig)
        {
            AppConfig = appConfig;
            NetConfig = new NetworkConfig()
            {
                IP             = netConfig.IP,
                Port           = netConfig.Port,
                EngineDllName  = netConfig.EngineDllName,
                MaxAcceptCount = netConfig.MaxAcceptCount,
                ThreadCount    = netConfig.ThreadCount,
                ProtocolOption = 0,
                ProtocolID     = 0,
                MaxBufferSize  = netConfig.MaxBufferSize,
                MaxPacketSize  = netConfig.MaxPacketSize,
            };

            var result = ServerNet.Init(NetConfig, null, null);

            if (result != NET_ERROR_CODE_N.SUCCESS)
            {
                return(new Tuple <bool, string>(false, result.ToString()));
            }

            if (ServerNet.Start(NetConfig.ProtocolID) == false)
            {
                return(new Tuple <bool, string>(false, NET_ERROR_CODE_N.NETWORK_START_FAIL.ToString()));
            }
            else
            {
                IsStartServerNetwork = true;
            }

            return(new Tuple <bool, string>(true, NET_ERROR_CODE_N.SUCCESS.ToString()));
        }
Esempio n. 8
0
        void CreateAndStartPacketSysytem(ServerAppConfig appConfig, int lobbyProcessThreadCount, int lobbyCountPerWorkPacketProcess)
        {
            MainPacketProcess = new MainPacketProcessSystem();
            MainPacketProcess.Init(appConfig, ServerNet, DBManager);

            SettingLobbyIDToPacketProcessIndexTable(appConfig.MaxLobbyCount, lobbyProcessThreadCount);

            for (int i = 0; i <= lobbyProcessThreadCount; ++i)
            {
                var process = new WorkPacketProcessSystem();
                process.Init(i+1, lobbyCountPerWorkPacketProcess, appConfig, ServerNet, DBManager);

                WorkPacketProcessList.Add(process);
            }

            RelayPacketPacketProcess.SetFunction(RelayPacketProcess);

            IsPacketDistributeThreadRunning = true;
            PacketDistributeThread = new System.Threading.Thread(this.DistributeProcket);
            PacketDistributeThread.Start();
        }