Exemplo n.º 1
0
 private void OnProcessTimedEvent(object sender, EventArgs e)
 {
     try
     {
         ProcessProcket();
         ProcessLog();
     }
     catch (Exception ex)
     {
         DevLog.Write(string.Format("[OnProcessTimedEvent] Exception:{0}", ex.ToString()), LOG_LEVEL.ERROR);
     }
 }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            IsStartServerNetwork = true;

            var result = ServerNet.Start(Config.ProtocolID);

            if (result)
            {
                DevLog.Write(string.Format("[Start] 네트워크 시작"), LOG_LEVEL.INFO);
            }
            else
            {
                DevLog.Write(string.Format("[Start] 네트워크 시작 실패"), LOG_LEVEL.ERROR);
            }
        }
Exemplo n.º 3
0
        public void Process(SFNETPacket packet)
        {
            var packetID = packet.PacketID();

            if (PacketHandlerMap.ContainsKey(packetID))
            {
                var user = UserManager.GetUser(packet.SessionID());

                PacketHandlerMap[packetID](packet, user);
            }
            else
            {
                DevLog.Write(string.Format("[PacketProcess] Invalid PacketID:{0}", packetID), LOG_LEVEL.ERROR);
            }
        }
Exemplo n.º 4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            workProcessTimer.Tick    += new EventHandler(OnProcessTimedEvent);
            workProcessTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
            workProcessTimer.Start();

            Config = new CgsfNET64Lib.NetworkConfig()
            {
                IP             = Properties.Settings.Default.IP,
                Port           = Properties.Settings.Default.Port,
                EngineDllName  = Properties.Settings.Default.EngineDllName,
                MaxAcceptCount = Properties.Settings.Default.MaxAcceptCount,
                ThreadCount    = Properties.Settings.Default.ThreadCount,
                ProtocolOption = 0,
                ProtocolID     = 0,
                MaxBufferSize  = Properties.Settings.Default.MaxBufferSize,
                MaxPacketSize  = Properties.Settings.Default.MaxPacketSize,
            };

            MaxLobbyCount     = Properties.Settings.Default.MaxLobbyCount;
            MaxLobbyUserCount = Properties.Settings.Default.MaxLobbyUserCount;


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

            if (result != CgsfNET64Lib.NET_ERROR_CODE_N.SUCCESS)
            {
                DevLog.Write(string.Format("[Init] 네트워크 라이브러리 초기화 실패. {0}, {1}", result.ToString(), result), LOG_LEVEL.ERROR);
                return;
            }

            IsStartServerNetwork = true;
            if (ServerNet.Start(Config.ProtocolID))
            {
                DevLog.Write(string.Format("[Start] 네트워크 시작"), LOG_LEVEL.INFO);
            }
            else
            {
                DevLog.Write(string.Format("[Start] 네트워크 시작 실패"), LOG_LEVEL.ERROR);
            }


            HandelrMgr.Create(ServerNet, MaxLobbyCount, MaxLobbyUserCount);


            SetGUIInfo();
            ConnectCountToGUI(0);
        }
Exemplo n.º 5
0
        private void ProcessProcket()
        {
            var packet = ServerNet.GetPacket();

            if (packet == null)
            {
                return;
            }

            switch (packet.GetPacketType())
            {
            case CgsfNET64Lib.SFPACKET_TYPE.CONNECT:
                SessionList.Add(packet.Serial());
                DevLog.Write(string.Format("[OnConnect] Serial:{0}", packet.Serial()), DevLog.LOG_LEVEL.INFO);
                break;

            case CgsfNET64Lib.SFPACKET_TYPE.DISCONNECT:
                SessionList.Remove(packet.Serial());
                DevLog.Write(string.Format("[OnDisConnect] Serial:{0}", packet.Serial()), DevLog.LOG_LEVEL.INFO);
                break;

            case CgsfNET64Lib.SFPACKET_TYPE.DATA:
                switch (packet.PacketID())
                {
                case PACKET_ID_ECHO:
                    string jsonstring = System.Text.Encoding.GetEncoding("utf-8").GetString(packet.GetData());
                    var    resData    = Newtonsoft.Json.JsonConvert.DeserializeObject <JsonPacketNoticeEcho>(jsonstring);
                    DevLog.Write(string.Format("[Chat] Serial:{0}, Msg:{1}", packet.Serial(), resData.Msg), DevLog.LOG_LEVEL.INFO);

                    var request = new JsonPacketNoticeEcho()
                    {
                        Msg = resData.Msg
                    };
                    var jsonstring2 = Newtonsoft.Json.JsonConvert.SerializeObject(request);
                    var bodyData    = Encoding.UTF8.GetBytes(jsonstring2);
                    ServerNet.SendPacket(packet.Serial(), PACKET_ID_ECHO, bodyData);
                    break;

                default:
                    DevLog.Write(string.Format("[ProcessProcket] Invalid PacketID:{0}", packet.PacketID()), DevLog.LOG_LEVEL.ERROR);
                    break;
                }
                break;
            }
        }
Exemplo n.º 6
0
        void ResponseEnterLobby(int sessionID, ERROR_CODE result, short lobbyID)
        {
            if (result == ERROR_CODE.NONE)
            {
                DevLog.Write(string.Format("[EnterLobby] lobbyID:{0}, sessionID:{1}", lobbyID, sessionID), LOG_LEVEL.INFO);
            }
            else
            {
                DevLog.Write(string.Format("[EnterLobby 실패] lobbyID:{0}, sessionID:{1}, result:{2}", lobbyID, sessionID, result.ToString()), LOG_LEVEL.ERROR);
            }

            var response = new JsonPacketResponseEnterLobby()
            {
                Result = result, LobbyID = lobbyID
            };

            ServerNetworkRef.Send <JsonPacketResponseEnterLobby>(sessionID, PACKET_ID.RESPONSE_ENTER_LOBBY, response);
        }
Exemplo n.º 7
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            workProcessTimer.Tick    += new EventHandler(OnProcessTimedEvent);
            workProcessTimer.Interval = new TimeSpan(0, 0, 0, 0, 32);
            workProcessTimer.Start();

            var result = ServerNet.Init(1, 16000, 4012);

            if (result)
            {
                var config = ServerNet.GetNetworkConfig();
                DevLog.Write(string.Format("[Init] IP:{0}, Port:{1}, EngineDllName:{2}", config.IP, config.Port, config.EngineDllName), LOG_LEVEL.INFO);
            }
            else
            {
                DevLog.Write(string.Format("[Init] 네트워크 라이브러리 초기화 실패"), LOG_LEVEL.ERROR);
            }
        }
Exemplo n.º 8
0
        private void ProcessProcket()
        {
            var packet = ServerNet.GetPacket();

            if (packet == null)
            {
                return;
            }

            switch (packet.GetPacketType())
            {
            case CgsfNET64Lib.SFPACKET_TYPE.CONNECT:
                SessionList.Add(packet.Serial());
                DevLog.Write(string.Format("[OnConnect] Serial:{0}", packet.Serial()), LOG_LEVEL.INFO);
                break;

            case CgsfNET64Lib.SFPACKET_TYPE.DISCONNECT:
                SessionList.Remove(packet.Serial());
                DevLog.Write(string.Format("[OnDisConnect] Serial:{0}", packet.Serial()), LOG_LEVEL.INFO);
                break;

            case CgsfNET64Lib.SFPACKET_TYPE.DATA:
                switch (packet.PacketID())
                {
                case PACKET_ID_ECHO:
                    var resData = JsonEnDecode.Decode <JsonPacketNoticeEcho>(packet.GetData());
                    DevLog.Write(string.Format("[Chat] Serial:{0}, Msg:{1}", packet.Serial(), resData.Msg), LOG_LEVEL.INFO);

                    var request = new JsonPacketNoticeEcho()
                    {
                        Msg = resData.Msg
                    };
                    var bodyData = JsonEnDecode.Encode <JsonPacketNoticeEcho>(request);
                    ServerNet.SendPacket(packet.Serial(), PACKET_ID_ECHO, bodyData);
                    break;

                default:
                    DevLog.Write(string.Format("[ProcessProcket] Invalid PacketID:{0}", packet.PacketID()), LOG_LEVEL.ERROR);
                    break;
                }
                break;
            }
        }