Example #1
0
        public void CreateStartServer()
        {
            ActiveServerBootstrap = BootstrapFactory.CreateBootstrap();

            if (!ActiveServerBootstrap.Initialize())
            {
                Console.WriteLine(string.Format("서버 초기화 실패"), LOG_LEVEL.ERROR);
                return;
            }
            else
            {
                var refAppServer = ActiveServerBootstrap.AppServers.FirstOrDefault() as MainServer;
                MainLogger = refAppServer.Logger;
                WriteLog("서버 초기화 성공", LOG_LEVEL.INFO);
            }


            var result = ActiveServerBootstrap.Start();

            if (result != StartResult.Success)
            {
                MainServer.WriteLog(string.Format("서버 시작 실패"), LOG_LEVEL.ERROR);
                return;
            }
            else
            {
                WriteLog("서버 시작 성공", LOG_LEVEL.INFO);
            }

            WriteLog(string.Format("서버 생성 및 시작 성공"), LOG_LEVEL.INFO);


            ChatServerEnvironment.Setting();

            StartRemoteConnect();

            var appServer = ActiveServerBootstrap.AppServers.FirstOrDefault() as MainServer;

            InnerMessageHostProgram.ServerStart(ChatServerEnvironment.ChatServerUniqueID, appServer.Config.Port);

            ClientSession.CreateIndexPool(appServer.Config.MaxConnectionNumber);
        }
        public bool DistributeRoomProcessor(bool isClientPacket, bool isPreRoomEnter, int roomNumber, ServerPacketData requestPacket)
        {
            var sessionIndex = requestPacket.SessionIndex;
            var processor    = PacketProcessorList.Find(x => x.관리중인_Room(roomNumber));

            if (processor != null)
            {
                if (isPreRoomEnter == false && SessionManager.IsStateRoom(sessionIndex) == false)
                {
                    MainServer.WriteLog("[DistributeRoomProcessor] - 방에 입장하지 않은 유저 - 1", LOG_LEVEL.DEBUG);
                    return(false);
                }

                processor.InsertMsg(isClientPacket, requestPacket);
                return(true);
            }

            MainServer.WriteLog("[DistributeRoomProcessor] - 방에 입장하지 않은 유저 - 2", LOG_LEVEL.DEBUG);
            return(false);
        }
Example #3
0
        public void RequestRoomEnter(ServerPacketData packetData)
        {
            var sessionID    = packetData.SessionID;
            var sessionIndex = packetData.SessionIndex;

            MainServer.WriteLog("RequestRoomEnter", LOG_LEVEL.DEBUG);

            try
            {
                var user = UserMgr.GetUser(sessionIndex);

                if (user == null || user.IsConfirm(sessionID) == false)
                {
                    ResponseEnterRoomToClient(ERROR_CODE.ROOM_ENTER_INVALID_USER, sessionID);
                    return;
                }

                if (SessionManager.EnableReuqestEnterRoom(sessionIndex) == false)
                {
                    ResponseEnterRoomToClient(ERROR_CODE.ROOM_ENTER_INVALID_STATE, sessionID);
                    return;
                }

                var reqData = MessagePackSerializer.Deserialize <PKTReqRoomEnter>(packetData.BodyData);

                var internalRoomEnter = MakeInternalRoomEnterPacket(reqData.RoomNumber, user.ID(), sessionID, sessionIndex);
                if (SendInternalRoomProcessor(true, reqData.RoomNumber, internalRoomEnter) == false)
                {
                    ResponseEnterRoomToClient(ERROR_CODE.ROOM_ENTER_ERROR_SYSTEM, sessionID);
                    return;
                }

                SessionManager.SetPreRoomEnter(sessionIndex, reqData.RoomNumber);

                MainServer.WriteLog("패킷 분배", LOG_LEVEL.DEBUG);
            }
            catch (Exception ex)
            {
                MainServer.WriteLog(ex.ToString(), LOG_LEVEL.DEBUG);
            }
        }
Example #4
0
        //dotnet ChatServer.dll --uniqueID 1 --roomMaxCountPerThread 16 --roomThreadCount 4 --roomMaxUserCount 4 --roomStartNumber 1 --dbWorkerThreadCount 4 --redisAddress 192.168.0.10 --maxUserCount 100
        static void Main(string[] args)
        {
            var serverOption = ParseCommandLine(args);

            if (serverOption == null)
            {
                return;
            }

            var workProcessTimer = new System.Timers.Timer(32);

            workProcessTimer.Elapsed += (s, e) => OnProcessTimedEvent(s, e);
            workProcessTimer.Start();

            var ServerApp = new MainServer();

            ServerApp.CreateStartServer();
            var error = ServerApp.CreateComponent();

            (error == CSBaseLib.ERROR_CODE.NONE).IfFalse(() =>
            {
                var errorMsg = string.Format("서버 컴포넌트 생성 실패. {0}: {1}", error, error.ToString());
                MainServer.WriteLog(errorMsg, CommonServerLib.LOG_LEVEL.INFO);
            });

            while (true)
            {
                System.Threading.Thread.Sleep(50);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    if (key.KeyChar == 'q')
                    {
                        Console.WriteLine("Server Terminate ~~~");
                        ServerApp.StopServer();
                        break;
                    }
                }
            }
        }
Example #5
0
        public void ResponseRoomEnterInternal(ServerPacketData packetData)
        {
            var sessionID    = packetData.SessionID;
            var sessionIndex = packetData.SessionIndex;

            MainServer.WriteLog("ResponseRoomEnterInternal", LOG_LEVEL.DEBUG);

            try
            {
                var resData = MessagePackSerializer.Deserialize <PKTInternalResRoomEnter>(packetData.BodyData);

                var user = UserMgr.GetUser(sessionIndex);

                if (user == null || user.ID() != resData.UserID)
                {
                    if (resData.Result == ERROR_CODE.NONE)
                    {
                        SendInternalRoomLeavePacket(resData.RoomNumber, resData.UserID);
                    }
                    return;
                }

                if (resData.Result != ERROR_CODE.NONE)
                {
                    SessionManager.SetStateLogin(sessionIndex);
                }
                else
                {
                    SessionManager.SetRoomEntered(sessionIndex, resData.RoomNumber);
                }

                ResponseEnterRoomToClient(resData.Result, sessionID);

                MainServer.WriteLog("ResponseRoomEnterInternal - Success", LOG_LEVEL.DEBUG);
            }
            catch (Exception ex)
            {
                MainServer.WriteLog(ex.ToString(), LOG_LEVEL.DEBUG);
            }
        }
Example #6
0
            public async void TryConnect(MainServer appServer)
            {
                IsTryConnecting = true;
                var activeConnector = appServer as SuperSocket.SocketBase.IActiveConnector;

                try
                {
                    var task = await activeConnector.ActiveConnect(Address);

                    if (task.Result)
                    {
                        Session = task.Session;
                    }
                }
                catch
                {
                }
                finally
                {
                    IsTryConnecting = false;
                }
            }
Example #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var serverOption = ParseCommandLine(args);

            if (serverOption == null)
            {
                return;
            }


            var serverApp = new MainServer();

            serverApp.InitConfig(serverOption);
            serverApp.CreateStartServer();
            MainServer.MainLogger.Info("Press q to shut down the server");

            while (true)
            {
                System.Threading.Thread.Sleep(50);
            }
        }
Example #8
0
        public void RequestLogin(ServerPacketData packetData)
        {
            var sessionID    = packetData.SessionID;
            var sessionIndex = packetData.SessionIndex;

            MainServer.WriteLog("로그인 요청 받음", LOG_LEVEL.DEBUG);

            try
            {
                if (SessionManager.EnableReuqestLogin(sessionIndex) == false)
                {
                    ResponseLoginToClient(ERROR_CODE.LOGIN_ALREADY_WORKING, packetData.SessionID);
                    return;
                }

                var reqData = MessagePackSerializer.Deserialize <PKTReqLogin>(packetData.BodyData);

                // 세션의 상태를 바꾼다
                SessionManager.SetPreLogin(sessionIndex);

                // DB 작업 의뢰한다.
                var dbReqLogin = new DBReqLogin()
                {
                    UserID    = reqData.UserID,
                    AuthToken = reqData.AuthToken
                };
                var jobDatas = MessagePackSerializer.Serialize(dbReqLogin);

                var dbQueue = MakeDBQueue(PACKETID.REQ_DB_LOGIN, sessionID, sessionIndex, jobDatas);
                RequestDBJob(ServerNetwork.GetPacketDistributor(), dbQueue);

                MainServer.WriteLog("DB에 로그인 요청 보냄", LOG_LEVEL.DEBUG);
            }
            catch (Exception ex)
            {
                // 패킷 해제에 의해서 로그가 남지 않도록 로그 수준을 Debug로 한다.
                MainServer.WriteLog(ex.ToString(), LOG_LEVEL.DEBUG);
            }
        }
Example #9
0
        void Process()
        {
            while (IsThreadRunning)
            {
                //System.Threading.Thread.Sleep(64); //테스트 용
                try
                {
                    var packet = MsgBuffer.Receive();

                    if (PacketHandlerMap.ContainsKey(packet.PacketID))
                    {
                        PacketHandlerMap[packet.PacketID](packet);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("세션 번호 {0}, PacketID {1}, 받은 데이터 크기: {2}", packet.SessionID, packet.PacketID, packet.BodyData.Length);
                    }
                }
                catch (Exception ex)
                {
                    IsThreadRunning.IfTrue(() => MainServer.WriteLog(ex.ToString(), LOG_LEVEL.ERROR));
                }
            }
        }
 public void Init(MainServer serverNetwork, UserManager userMgr)
 {
     ServerNetwork = serverNetwork;
     UserMgr       = userMgr;
 }
Example #11
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MainServer mainServer = new MainServer();

            mainServer.Show();
        }
 void RegistPacketHandler(MainServer serverNetwork)
 {
     CommonPacketHandler.Init(serverNetwork, UserMgr);
     CommonPacketHandler.RegistPacketHandler(PacketHandlerMap);
 }
Example #13
0
 public void Init(MainServer serverNetwork, ConnectSessionManager sessionManager)
 {
     ServerNetwork  = serverNetwork;
     SessionManager = sessionManager;
 }