예제 #1
0
 private void StartNow(List <MatchPlayer> m_players, Server server)
 {
     LastStartTime = JHSTime.Time;
     if (DbManager == null)
     {
         DbManager = AccountManager.Instance;
     }
     for (int i = 0; i < m_players.Count; i++)
     {
         MatchPlayer parti = m_players[i];
         if (parti != null)
         {
             AccountOBJ user = DbManager.GetOnlineByConnectionId(parti.ConnectionId);
             if (user != null && user.InQueue && user.IsOnline)
             {
                 lock (user)
                     user.InQueue = false;
                 JHSNetworkServer.Send(user.connectionID, NetworkConstants.START_SEARCH_MATCH, new SearchMatch()
                 {
                     op = Enums.SearchMatchOperations.START, IP = server.IP, port = server.port
                 });
             }
         }
     }
 }
예제 #2
0
        public void Start()
        {
            foreach (KeyValuePair <short, IJHSInterface> that in m_MessageHandlersDict)
            {
                JHSNetworkServer.RegisterHandler(that.Key, OnNetworkReceive);
            }

            JHSNetworkServer.Start();
        }
예제 #3
0
 public void RegisterHandeler(short id, IJHSInterface handler)
 {
     if (!m_MessageHandlersDict.ContainsKey(id))
     {
         JHSNetworkServer.RegisterHandler(id, OnNetworkReceive);
         m_MessageHandlersDict[id] = handler;
     }
     else
     {
         LOG.Error("Network Handler " + id + " already exist.");
     }
 }
예제 #4
0
 public void SendToAll(string userName, string msg, long timeStamp)
 {
     lock (views)
     {
         ChatMsg packet = new ChatMsg()
         {
             username = userName,
             date     = (ulong)timeStamp,
             msg      = msg
         };
         uint[] cons = views.ToArray();
         for (int i = 0; i < cons.Length; i++)
         {
             JHSNetworkServer.Send(cons[i], NetworkConstants.CHAT, packet);
         }
     }
 }
예제 #5
0
    public void Connect()
    {
        JHSNetworkServer.RegisterHandler(InternalMessages.DISCONNECT, OnDisconnect);
        //    JHSNetworkServer.RegisterHandler(InternalMessages.RECIEVE, OnNetworkReceive);
        RegisterHandeler(NetworkConstants.LOGIN, new LoginHandler());
        RegisterHandeler(NetworkConstants.REGISTER, new RegisterHandler());
        RegisterHandeler(NetworkConstants.UPDATE_SITE_DATA, new UpdateSiteDataHandler());
        RegisterHandeler(NetworkConstants.GET_NEW_URL, new Ask4NewUrlHandler());
        RegisterHandeler(NetworkConstants.CHAT, new ChatHandler());
        RegisterHandeler(NetworkConstants.OPEN_CHAT, new ChatOpenHandler());
        string ListenIP   = Program.configs.GetValue <string>("HOST");
        int    ListenPort = Program.configs.GetValue <int>("PORT");
        int    password   = Program.configs.GetValue <int>("ServerPassword");
        int    Version    = Program.configs.GetValue <int>("Version");

        JHSNetworkServer.Start(ListenIP, ListenPort);
        LOG.Error("No error, server started!");
    }
예제 #6
0
        public void InitHandlers()
        {
            JHSNetworkServer.RegisterHandler(InternalMessages.DISCONNECT, OnDisconnect);
            JHSNetworkServer.RegisterHandler(InternalMessages.RECIEVE, OnNetworkReceive);
            RegisterHandeler(NetworkConstants.LOGIN, new UserLogin());
            RegisterHandeler(NetworkConstants.BUYCOLORCHANGE, new BuyColorChange());
            RegisterHandeler(NetworkConstants.EXCHANGE, new ExchangeCurrency());
            RegisterHandeler(NetworkConstants.BUYCHARACTER, new BuySkinHandler());
            RegisterHandeler(NetworkConstants.GM, new GMComands());
            RegisterHandeler(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterCommand());
            RegisterHandeler(NetworkConstants.START_SEARCH_MATCH, new SearchMatchCommand());
            RegisterHandeler(NetworkConstants.COLLECT_ACTIVE, new CollectActiveCommand());
            RegisterHandeler(NetworkConstants.REFRESH_ACTIVES, new RequestActives());
            RegisterHandeler(NetworkConstants.UPDATE_RANKINGS, new GetRankings());

            //GAME SERVER PACKETS
            RegisterHandeler(GameServerOP.PUTROLE, new CMD_GS_GIVE_REWARDS());
            RegisterHandeler(GameServerOP.GETROLE, new CMD_GETROLE());
            RegisterHandeler(GameServerOP.UPDATE_STATE, new GS_STATE());
        }
예제 #7
0
        public bool Execute(JHSNetworkMessage netMsg)
        {
            if (DbManager == null)
            {
                DbManager = AccountManager.Instance;
            }

            GWLoginPacket packet = netMsg.ReadMessage <GWLoginPacket>();

            if (packet != null)
            {
                uint connectionId = netMsg.conn.connectionId;

                AccountOBJ user = DbManager.GetAccountFromDbByUserName(packet.LoginName);
                if (user != null)
                {
                    lock (user)
                    {
                        string userName = user.Username;
                        if (userName.VerifyPassword(user.Password, packet.Password))
                        {
                            //RESPONSE LOGIC
                            lock (user)
                            {
                                user.connectionID = connectionId;
                                user.LoginTime    = DateTime.Now;
                                user.LastKnownIp  = user.Ip;
                                user.Ip           = netMsg.conn.IP;
                                user.OnLogin();
                                DbService.SubmitUpdate2Queue(user);
                            }
                            //  RankinData ranking = rankingManager.GetUser(user);

                            GWLoginResponsePacket dat = new GWLoginResponsePacket
                            {
                                actives        = user.GetActiveCompleate(),
                                characters     = user.SerializeChars(),
                                RESPONSE       = SUCCESS,
                                League         = user.League,
                                LeaguePosition = user.LeaguePosition,
                                LEGUE_STATUS   = user.LegueStatus,
                                PlayerNick     = user.PlayerName,
                                Gold           = (uint)user.Gold,
                                Silver         = (uint)user.Silver,
                                Priviledge     = (byte)user.Priviledge,
                                LoginTocken    = user.Id,
                                LEVEL          = (uint)user.Data.Level,
                                EXP            = (uint)user.Data.Exp,
                                IsPushLevelUp  = user.LevelUpNotify,
                                SEASON         = (byte)Settings.RANKING_SEASON,
                                GameCount      = user.GameCount < Settings.MIN_GAMES_TO_DECIDE_RANKING_SKILLS ? (byte)(Settings.MIN_GAMES_TO_DECIDE_RANKING_SKILLS - user.GameCount)  : (byte)0
                            };

                            DbManager.RegisterOnline(connectionId, user);
                            JHSNetworkServer.Send(connectionId, NetworkConstants.LOGIN, dat);
                        }
                        else
                        {
                            JHSNetworkServer.Send(connectionId, NetworkConstants.LOGIN, new GWLoginResponsePacket()
                            {
                                RESPONSE = WRONG_PASSWORD_OR_LOGIN
                            });
                        }
                    }
                }
                else
                {
                    if (Settings.AutoCreate)
                    {
                        user = CreateAccount(packet);
                        lock (user)
                        {
                            user.connectionID = connectionId;
                            user.LoginTime    = DateTime.Now;
                            user.LastKnownIp  = user.Ip;
                            user.Ip           = netMsg.conn.IP;
                            user.OnLogin();
                            DbService.UpdateEntityIntime(user);
                        }
                        user = DbManager.GetAccountFromDbByUserName(packet.LoginName);
                        if (user != null)
                        {
                            GWLoginResponsePacket dat = new GWLoginResponsePacket
                            {
                                actives        = user.GetActiveCompleate(),
                                characters     = user.SerializeChars(),
                                RESPONSE       = SUCCESS,
                                League         = user.League,
                                LeaguePosition = user.LeaguePosition,
                                LEGUE_STATUS   = user.LegueStatus,
                                PlayerNick     = user.PlayerName,
                                Gold           = (uint)user.Gold,
                                Silver         = (uint)user.Silver,
                                Priviledge     = (byte)user.Priviledge,
                                LoginTocken    = user.Id,
                                LEVEL          = (uint)user.Data.Level,
                                EXP            = (uint)user.Data.Exp,
                                IsPushLevelUp  = user.LevelUpNotify,
                                SEASON         = (byte)Settings.RANKING_SEASON,
                                GameCount      = user.GameCount < 5 ? (byte)(5 - user.GameCount) : (byte)0
                            };
                            DbManager.RegisterOnline(connectionId, user);
                            JHSNetworkServer.Send(connectionId, NetworkConstants.LOGIN, dat);
                        }
                    }
                    else
                    {
                        JHSNetworkServer.Send(connectionId, NetworkConstants.LOGIN, new GWLoginResponsePacket()
                        {
                            RESPONSE = USER_NOT_FOUND
                        });
                    }
                }
            }

            return(true);
        }