예제 #1
0
        public void ReceiverProperty_ConstructorWithParameters_ReturnsGivenValues(ECode code, int receiverValue)
        {
            var result = new ReceiverProperty(code, receiverValue);

            Assert.AreEqual(result.Code, code);
            Assert.AreEqual(result.ReceiverValue, receiverValue);
        }
 public FailException(ECode code, string msg, object data = null)
     : base(msg)
 {
     this.code = code;
     this.msg  = msg;
     this.data = data;
 }
예제 #3
0
 /// <summary>
 /// Builder Internal Orders
 /// </summary>
 /// <param name="numberOrder">Number order</param>
 /// <param name="nameDevice">Code the devices</param>
 /// <param name="eTypeDevice">Type the devices</param>
 /// <param name="countDevice">Count the devices</param>
 public InternalOrder(int numberOrder, ECode nameDevice, EType eTypeDevice, int countDevice)
 {
     this.numberOrder = numberOrder;
     this.nameDevice  = nameDevice;
     this.eTypeDevice = eTypeDevice;
     this.countDevice = countDevice;
 }
예제 #4
0
 /// <summary>
 /// 基础数据类型
 /// </summary>
 /// <param name="code">ECode</param>
 /// <param name="data">泛型</param>
 public BasicsResponse(ECode code, T data)
 {
     Code    = code;
     Message = code.Desc();
     if (data == null)
     {
         data = default(T);
     }
     Data = data;
 }
예제 #5
0
        public Boss[] GetBossTable(out ECode ec)
        {
            Boss[] obj = null;
            ec = ECode.None;

            try
            {
                obj = DBCon.QueryBossTable();
            } catch (DatabaseException ex) {
                ec = ex.ErrorCode;
            }
            return(obj);
        }
예제 #6
0
        public int GetBossCount(out ECode ec)
        {
            int count = -1;

            ec = ECode.None;

            try
            {
                count = DBCon.QueryBossCount();
            } catch (DatabaseException ex) {
                ec = ex.ErrorCode;
            }
            return(count);
        }
예제 #7
0
        public Boss GetBoss(int id, out ECode ec)
        {
            Boss obj = null;

            ec = ECode.None;

            try
            {
                obj = DBCon.QueryBoss(id);
            } catch (DatabaseException ex) {
                ec = ex.ErrorCode;
            }
            return(obj);
        }
예제 #8
0
        public Hero GetHero(int id, out ECode ec)
        {
            Hero obj = null;

            ec = ECode.None;

            try
            {
                obj = DBCon.QueryHero(id);
            } catch (DatabaseException ex) {
                ec = ex.ErrorCode;
            }
            return(obj);
        }
예제 #9
0
        public User GetUser(int id, out ECode ec)
        {
            User obj = null;

            ec = ECode.None;

            try
            {
                obj = DBCon.QueryUser(id);
            } catch (DatabaseException ex) {
                ec = ex.ErrorCode;
            }
            return(obj);
        }
예제 #10
0
        public int GetUserId(string username, out ECode ec)
        {
            int id = -1;

            ec = ECode.None;

            try
            {
                id = DBCon.QueryUserId(username);
            } catch (DatabaseException ex) {
                ec = ex.ErrorCode;
            }
            return(id);
        }
예제 #11
0
        public string[] QueryFriends(string token, out ECode ec)
        {
            ec = ECode.None;
            string[] result = null;

            try
            {
                UserSession session = (UserSession)UserRegistry.GetClientSession(token);
                result = session.UserData.Friends;
            } catch (NullReferenceException) {
                ec = ECode.QueryError;
            }

            return(result);
        }
예제 #12
0
        public PlayerListing QueryPlayerListing(string userToken, out ECode ec)
        {
            ec = ECode.None;
            PlayerListing playerListing = null;

            if (PlayerRegistry.IsClientRegistered(userToken))
            {
                playerListing = GetPlayerListing();
            }
            else
            {
                ec = ECode.AuthenticationFail;
            }

            return(playerListing);
        }
예제 #13
0
        public GameListing QueryGameServers(string token, out ECode ec)
        {
            ec = ECode.None;
            GameListing gsl = null;

            if (UserRegistry.IsClientRegistered(token))
            {
                gsl = GenerateGameServerListing();
            }
            else
            {
                ec = ECode.AuthenticationFail;
            }

            return(gsl);
        }
예제 #14
0
        public bool JoinGameServer(string userPuid, string userToken, out ECode ec)
        {
            ec = ECode.None;
            bool success = false;
            IGameServerController_Callback callbackChannel // Get player callback object to store
                = OperationContext.Current.GetCallbackChannel <IGameServerController_Callback>();

            try
            {
                if (PlayerRegistry.GetCount() >= MAX_PLAYERS)
                {
                    ec = ECode.ServerFull;
                    Console.WriteLine("> Rejected Player Join: @username:{" + userPuid + "} token:{" + userToken + "}");
                }
                else if (PlayerRegistry.IsClientRegistered(userToken))
                {
                    ((PlayerSession)PlayerRegistry.GetClientSession(userToken)).CallbackChannel = callbackChannel; // update callback channel
                    success = true;
                    Console.WriteLine("> Old Player Join: @username:{" + userPuid + "} token:{" + userToken + "}");
                }
                else if (GPSConnection.IsUserTokenVaild(userToken))
                {
                    // Register Player //
                    PlayerSession ps = new PlayerSession(userPuid, "", PLAYER_LIFESPAN, callbackChannel, null);
                    PlayerRegistry.RegisterClient(userToken, ps);
                    success = true;
                    Console.WriteLine("> New Player Join: @username:{" + userPuid + "} token:{" + userToken + "}");

                    // Notify others of event //
                    AdvertiseToPortal_UserJoin(userPuid);
                    //BroadcastToPlayers_PlayerStatus(userPuid);
                    if (Game != null && Game.HasGameStarted() == false)
                    {   // Notify players if this will change game state
                        BroadcastToPlayers_GameReady(Game.ArePlayersAllowedToEnterGame());
                    }
                }
                else
                {
                    Console.WriteLine("> Invalid Player Join: @username:{" + userPuid + "} token:{" + userToken + "}");
                }
            } catch (ServerConnectionException ex) {
                ec = ex.ErrorCode;
                Console.WriteLine("> Failed Player Join: @username:{" + userPuid + "} token:{" + userToken + "}");
            }

            return(success);
        }
예제 #15
0
파일: WriterSvc.cs 프로젝트: Dzoni1999/RES
        public void GenerateRandomValue()
        {
            code = (ECode)ran.Next(Enum.GetNames(typeof(ECode)).Length);

            // Codes
            if (code == ECode.CODE_DIGITAL)
            {
                value = GetRandomValue() % 2;
            }

            else if (code == ECode.CODE_ANALOG)
            {
                value = GetRandomValue() + 1000;
            }

            else if (code == ECode.CODE_CONSUMER)
            {
                value = GetRandomValue() + 2000;
            }

            else if (code == ECode.CODE_CUSTOM)
            {
                value = GetRandomValue() + 3000;
            }

            else if (code == ECode.CODE_LIMITSET)
            {
                value = GetRandomValue() + 4000;
            }

            else if (code == ECode.CODE_MULTIPLENODE)
            {
                value = GetRandomValue() + 5000;
            }

            else if (code == ECode.CODE_SINGLENODE)
            {
                value = GetRandomValue() + 6000;
            }

            else //if (code == Code.CODE_SOURCE)
            {
                value = GetRandomValue() + 7000;
            }
        }
예제 #16
0
        public int AuthenticateCredentials(string username, string password, out ECode ec)
        {
            int id = -1;

            ec = ECode.None;

            try
            {
                id = DBCon.QueryUserId(username);
                if (id != -1 && !DBCon.QueryUserPassword(id).Equals(password))
                {
                    id = -1;
                }
            } catch (DatabaseException ex) {
                ec = ex.ErrorCode;
            }
            return(id);
        }
예제 #17
0
        public void ReadDataFromDataBase()
        {
            try
            {
                ReplicatorDbContext _context = new ReplicatorDbContext();

                string        dateFrom = "2020-06-13 16:58:02.347";
                string        dateTo   = "2020-06-13 16:58:02.677";
                Reader.Reader reader   = new Reader.Reader(1);

                ECode c         = ECode.CODE_ANALOG;
                int   datasetID = 1;
                reader.service.ReadDataFromDataBase(c, datasetID, _context, dateFrom, dateTo);

                c = ECode.CODE_DIGITAL;
                reader.service.ReadDataFromDataBase(c, datasetID, _context, dateFrom, dateTo);

                c         = ECode.CODE_CUSTOM;
                datasetID = 2;
                reader.service.ReadDataFromDataBase(c, datasetID, _context, dateFrom, dateTo);

                c = ECode.CODE_LIMITSET;
                reader.service.ReadDataFromDataBase(c, datasetID, _context, dateFrom, dateTo);

                c         = ECode.CODE_SINGLENODE;
                datasetID = 3;
                reader.service.ReadDataFromDataBase(c, datasetID, _context, dateFrom, dateTo);

                c = ECode.CODE_MULTIPLENODE;
                reader.service.ReadDataFromDataBase(c, datasetID, _context, dateFrom, dateTo);

                c         = ECode.CODE_CONSUMER;
                datasetID = 4;
                reader.service.ReadDataFromDataBase(c, datasetID, _context, dateFrom, dateTo);

                c = ECode.CODE_SOURCE;
                reader.service.ReadDataFromDataBase(c, datasetID, _context, dateFrom, dateTo);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
            Assert.Pass();
        }
예제 #18
0
        public void SubmitPlayerMove(string userToken, PlayerMove move, out ECode ec)
        {
            ec = ECode.None;

            if (PlayerRegistry.IsClientRegistered(userToken))
            {
                PlayerSession ps = (PlayerSession)PlayerRegistry.GetClientSession(userToken);
                try
                {
                    ps.Move = move;
                } catch (NullReferenceException) {
                    ec = ECode.QueryError;
                }
            }
            else
            {
                ec = ECode.AuthenticationFail;
            }
        }
예제 #19
0
        /* returns null if:
         *      - already logged in
         *      - database connection failed
         *      - database authentication failed
         *      - user data is null
         *      - username is null
         */
        public string Login(string address, string username, string password, out ECode ec)
        {
            ec = ECode.None;
            string token = null;
            IUserPortalServerController_Callback callbackChannel
                = OperationContext.Current.GetCallbackChannel <IUserPortalServerController_Callback>();

            try
            {
                // Check credentials against database //
                int id = DSConnection.AuthenticateCredentials(username, password);
                if (id != -1) // valid
                {
                    // Check if already logged in //
                    if (UserRegistry.IsPuidRegistered(username) == false)
                    {
                        // Log in User //
                        User        user    = DSConnection.GetUser(id);
                        UserSession session = new UserSession(username, address, USER_LIFESPAN, callbackChannel, user);
                        token = UserRegistry.RegisterClient(session);
                        Console.WriteLine("> New Login: @username:{" + username + "} token:{" + token + "}");
                    }
                    else
                    {                                                                                          // Retrieve existing session token //
                        token = UserRegistry.GetToken(username);
                        ((UserSession)UserRegistry.GetClientSession(token)).CallbackChannel = callbackChannel; // update callback channel
                        Console.WriteLine("> Old Login: @username:{" + username + "} token:{" + token + "}");
                    }
                }
                else
                {
                    Console.WriteLine("> Failed Login: @username:{" + username + "}");
                }
            } catch (DataServerException ex) {
                // occurs if any of the database queries fail
                ec = ex.ErrorCode;
            } catch (ArgumentNullException) {
                // occurs if username or user data is null
                ec = ECode.QueryError;
            }
            return(token);
        }
예제 #20
0
        public string RegisterGameServer(string address, string serverName, out ECode ec)
        {
            ec = ECode.None;
            string token     = null;
            bool   collision = false;

            try
            {
                // Check for GameServer collisions //
                collision = (GameRegistry.IsPuidRegistered(serverName)); // Check if already registered
                if (collision == false)
                {
                    // Check for server address collisions
                    foreach (KeyValuePair <string, ClientSession> kvp in GameRegistry)
                    {
                        if (collision == false) // If no collision detected, check for collision
                        {
                            collision = (kvp.Value.ClientAddress == address);
                        }
                    }
                }

                if (collision)
                {
                    ec = ECode.QueryError;
                    Console.WriteLine("> GameServer registration collision: @ServerName:{" + serverName + "}");
                }
                else
                {
                    IGamePortalServerController_Callback callbackChannel
                        = OperationContext.Current.GetCallbackChannel <IGamePortalServerController_Callback>();
                    GameSession session = new GameSession(serverName, address, GAME_LIFESPAN, callbackChannel);
                    token = GameRegistry.RegisterClient(session);
                    Console.WriteLine("> New GameServer registration: @ServerName:{" + serverName + "} token:{" + token + "}");
                }
            } catch (ArgumentNullException) {
                // occurs if serverName or address is null
                ec = ECode.QueryError;
            }

            return(token);
        }
예제 #21
0
        public void LeaveGameServer(string userPuid, string userToken)
        {
            ECode ec = ECode.None;

            try
            {
                Server.LeaveGameServer(userPuid, userToken, out ec);
            } catch (ArgumentNullException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            } catch (CommunicationException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            } catch (TimeoutException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            }

            if (ec != ECode.None)
            {
                throw new GameServerException(ec, "Internal error occurred at: LeaveGameServer()");
            }
        }
예제 #22
0
        public void SubmitPlayerHero(string userToken, int heroId)
        {
            ECode ec = ECode.None;

            try
            {
                Server.SubmitPlayerHero(userToken, heroId, out ec);
            } catch (ArgumentNullException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            } catch (CommunicationException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            } catch (TimeoutException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            }

            if (ec != ECode.None)
            {
                throw new GameServerException(ec, "Internal error occurred at: SubmitPlayerHero()");
            }
        }
예제 #23
0
        public void UnregisterGameServer(string token)
        {
            ECode ec = ECode.None;

            try
            {
                Server.UnregisterGameServer(token, out ec);
            } catch (ArgumentNullException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            } catch (CommunicationException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            } catch (TimeoutException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            }

            if (ec != ECode.None)
            {
                throw new PortalServerException(ec, "Internal error occurred at: DeregisterGameServer()");
            }
        }
예제 #24
0
        public void SubmitPlayerHero(string userToken, int heroId, out ECode ec)
        {
            ec = ECode.None;

            if (PlayerRegistry.IsClientRegistered(userToken))
            {
                PlayerSession ps = (PlayerSession)PlayerRegistry.GetClientSession(userToken);
                try
                {
                    ps.PlayerHero = DSConnection.GetHero(heroId); // Change to get Hero from local catched copy
                } catch (NullReferenceException) {
                    ec = ECode.QueryError;
                } catch (DataServerException) {
                    ec = ECode.QueryError;
                }
            }
            else
            {
                ec = ECode.AuthenticationFail;
            }
        }
예제 #25
0
        public string[] QueryFriendsOnline(string token, out ECode ec)
        {
            ec = ECode.None;
            string[] result  = null;
            string[] friends = QueryFriends(token, out ec);

            if (friends != null)
            {
                List <string> matches = new List <string>();
                foreach (string username in friends)
                {
                    if (UserRegistry.IsPuidRegistered(username))
                    {
                        matches.Add(username);
                    }
                }
                result = matches.ToArray();
            }

            return(result);
        }
예제 #26
0
        public Hero[] GetHeroTable(string token, out ECode ec)
        {
            ec = ECode.None;
            Hero[] heroes = null;

            if (UserRegistry.IsTokenRegistered(token))
            {
                try
                {
                    heroes = DSConnection.GetHeroTable();
                } catch (ServerConnectionException) {
                    ec = ECode.ConnectionError;
                } catch (DataServerException) {
                    ec = ECode.QueryError;
                }
            }
            else
            {
                ec = ECode.AuthenticationFail;
            }

            return(heroes);
        }
예제 #27
0
 public static int GetDatasetForCode(ECode code1, ECode code2)
 {
     if (code1 == ECode.CODE_ANALOG && code2 == ECode.CODE_DIGITAL)
     {
         return(1);
     }
     else if (code1 == ECode.CODE_CUSTOM && code2 == ECode.CODE_LIMITSET)
     {
         return(2);
     }
     else if (code1 == ECode.CODE_SINGLENODE && code2 == ECode.CODE_MULTIPLENODE)
     {
         return(3);
     }
     else if (code1 == ECode.CODE_CONSUMER && code2 == ECode.CODE_SOURCE)
     {
         return(4);
     }
     else
     {
         return(0);
     }
 }
예제 #28
0
        //////////////////////////////////////////////////

        public string RegisterGameServer(string address, string serverName)
        {
            ECode  ec    = ECode.None;
            string value = null;

            try
            {
                value = Server.RegisterGameServer(address, serverName, out ec);
            } catch (ArgumentNullException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, address, ERRMSG_CONNECTION, ex);
            } catch (CommunicationException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, address, ERRMSG_CONNECTION, ex);
            } catch (TimeoutException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, address, ERRMSG_CONNECTION, ex);
            }

            if (ec != ECode.None)
            {
                throw new PortalServerException(ec, "Internal error occurred at: RegisterGameServer()");
            }

            return(value);
        }
예제 #29
0
        public GameListing QueryGameServers(string token)
        {
            ECode       ec    = ECode.None;
            GameListing value = null;

            try
            {
                value = Server.QueryGameServers(token, out ec);
            } catch (ArgumentNullException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            } catch (CommunicationException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            } catch (TimeoutException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, null, ERRMSG_CONNECTION, ex);
            }

            if (ec != ECode.None)
            {
                throw new PortalServerException(ec, "Internal error occurred at: QueryGameServers()");
            }

            return(value);
        }
예제 #30
0
        //////////////////////////////////////////////////

        public string Login(string address, string username, string password)
        {
            ECode  ec    = ECode.None;
            string value = null;

            try
            {
                value = Server.Login(address, username, password, out ec);
            } catch (ArgumentNullException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, address, ERRMSG_CONNECTION, ex);
            } catch (CommunicationException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, address, ERRMSG_CONNECTION, ex);
            } catch (TimeoutException ex) {
                throw new ServerConnectionException(ECode.ConnectionError, address, ERRMSG_CONNECTION, ex);
            }

            if (ec != ECode.None)
            {
                throw new PortalServerException(ec, "Internal error occurred at: Login()");
            }

            return(value);
        }