コード例 #1
0
ファイル: Character.cs プロジェクト: xDragonZ/GhostServer
        public Character(int id = 0, GhostClient gc = null)
        {
            this.ID     = id;
            this.Client = gc;

            this.Items = new CharacterItems(this);
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: Vasiliauskas/TheEmpire
        protected bool TakeTurn()
        {
            var view = _service.GetPlayerView();

            _lastTurn = view.Turn;
            try
            {
                Console.WriteLine($"Taking Turn {view.Mode}");

                IEnumerable <Position> req = null;
                if (view.Mode == "TECMAN")
                {
                    req = new TacManClient().PerformMove(view);
                }
                else
                {
                    req = new GhostClient().PerformMove(view);
                }

                var responseMove = _service.PerformMove(req);
                var positions    = string.Join(" ", req.Select(c => $"{c.Col}.{c.Row}"));
                Console.WriteLine($"Moving to {positions}");
                Console.WriteLine($"Moving from ghosts {string.Join(" ", view.PreviousGhostPositions.Select(c => $"{c.Col}.{c.Row}"))}");
                Console.WriteLine($"Moving from tecman {view.PreviousTecmanPosition.Col}, {view.PreviousTecmanPosition.Col}");
                Console.WriteLine($"Move response {responseMove.Message}");
                Console.WriteLine($"Move response {responseMove.Status}");
                // pratesti algo
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Taking Turn {_lastTurn}failed: " + ex.Message);
                return(false);
            }
            return(true);
        }
コード例 #3
0
ファイル: Character.cs プロジェクト: york8817612/GhostServer
        public Character(int id = 0, GhostClient gc = null)
        {
            this.ID = id;
            this.Client = gc;

            this.Items = new CharacterItems(this);
        }
コード例 #4
0
        public static void Check_SameName_Req(LittleEndianAccessor lea, GhostClient gc)
        {
            lea.readInt();
            lea.readInt();
            string name = lea.readAsciiString(20);

            gc.SendPacket(net.Packet.Chars.Check_SameName_Ack((Database.Exists("Characters", "name = '{0}'", name) ? 0 : 1)));
        }
コード例 #5
0
        public static void Delete_MyChar_Req(LittleEndianAccessor lea, GhostClient gc)
        {
            lea.readInt();
            lea.readInt();
            int del_id = lea.readInt();

            gc.Account.Characters[del_id].Delete();

            gc.SendPacket(net.Packet.Chars.Delete_MyChar_Ack(del_id + 1));
        }
コード例 #6
0
        public async Task GetPostsAsync_WithSlug_RequestsToCorrectEndpoint()
        {
            var mockHttp     = CreateMockHttp($"{PostsEndpoint}slug/welcome?fields=title%2cslug%2chtml%2cpublished_at&key=content_api_key", "{}");
            var ghostClient  = new GhostClient(mockHttp.ToHttpClient(), ApiUrl, ContentApiKey);
            var queryBuilder = new GhostQueryBuilder <PostContent>()
                               .Slug("welcome");

            await ghostClient.GetPostsAsync(queryBuilder);

            mockHttp.VerifyNoOutstandingExpectation();
        }
コード例 #7
0
        /* state
         * 28 = 此為有年齡限制的頻道,請使用其他頻道
         * 04 = 此ID已連線,請稍後再試
         * else = 網路狀態錯誤
         */
        public static byte[] Game_Ack(GhostClient c, int state)
        {
            PacketLittleEndianWriter plew = new PacketLittleEndianWriter();

            plew.write((byte)SendOperationCode.Login.GAME_ACK);
            plew.write((byte)state);
            plew.writeGhostAsciiString("192.168.1.101");
            plew.writeInt(14101 + c.CharSID);
            plew.writeInt(14199);

            return(plew.getPacket());
        }
コード例 #8
0
        public async Task GetPostsAsync_ThrowsException_WhenApiReturnsInvalidData()
        {
            var invalidResponse = "123";
            var mockHttp        = CreateMockHttp($"{PostsEndpoint}?fields=title%2cslug%2chtml%2cpublished_at&key=content_api_key", invalidResponse);
            var ghostClient     = new GhostClient(mockHttp.ToHttpClient(), ApiUrl, ContentApiKey);
            var queryBuilder    = new GhostQueryBuilder <PostContent>();

            await Assert.ThrowsAsync <InvalidOperationException>(async() =>
            {
                await ghostClient.GetPostsAsync(queryBuilder);
            });

            mockHttp.VerifyNoOutstandingExpectation();
        }
コード例 #9
0
ファイル: Login.cs プロジェクト: xDragonZ/GhostServer
        public static void Login_Req(LittleEndianAccessor lea, GhostClient gc)
        {
            string username = lea.readGhostAsciiString();
            string password = lea.readGhostAsciiString();

            if (username.IsAlphaNumeric() == false)
            {
                gc.SendPacket(net.Packet.Login.Login_Ack(13, false));
                return;
            }

            gc.Account = new Account(gc);
            try
            {
                gc.Account.Load(username);

                if (password != gc.Account.Password)
                {
                    gc.SendPacket(net.Packet.Login.Login_Ack(14, false));
                }
                else if (gc.Account.Banned > 0)
                {
                    gc.SendPacket(net.Packet.Login.Login_Ack(12, false));
                }
                else
                {
                    if (gc.Account.Master > 0)
                    {
                        gc.SendPacket(net.Packet.Login.Login_Ack(0, true));
                    }
                    else
                    {
                        gc.SendPacket(net.Packet.Login.Login_Ack(0, false));
                    }
                    gc.Account.LoggedIn = 1;
                }
            }
            catch (Exception ee)
            {
                if (ee.Message.Equals("account does not"))
                {
                    gc.SendPacket(net.Packet.Login.Login_Ack(13, false));
                }
                else
                {
                    Log.Error(ee.ToString());
                }
            }
        }
コード例 #10
0
ファイル: Chars.cs プロジェクト: xDragonZ/GhostServer
        public static byte[] MyChar_Info_Ack(GhostClient gc, List <Character> chars)
        {
            PacketLittleEndianWriter plew = new PacketLittleEndianWriter();

            plew.writeShort((short)SendOperationCode.Chars.MYCHAR_INFO_ACK);
            plew.writeInt(0);           // length + CRC
            plew.writeInt(0);
            plew.writeInt(chars.Count); // Characters.Count

            for (int i = 0; i < 4; i++)
            {
                getCharactersData(plew, (i < chars.Count) ? chars[i] : null);
            }

            return(plew.getPacket());
        }
コード例 #11
0
        public async Task GetPostsAsync_ReturnsCorrectly()
        {
            var actualGhostResponse = TestData.GhostResponseJson;
            var mockHttp            = CreateMockHttp(
                $"{PostsEndpoint}?fields=title%2cslug%2chtml%2cpublished_at&key=content_api_key", actualGhostResponse);

            var ghostClient  = new GhostClient(mockHttp.ToHttpClient(), ApiUrl, ContentApiKey);
            var queryBuilder = new GhostQueryBuilder <PostContent>();

            // Act
            var actual = await ghostClient.GetPostsAsync(queryBuilder);

            var expected = TestData.PostsResponse;

            Assert.Equal(expected.Posts, actual?.Posts);
            Assert.Equal(expected.Meta, actual?.Meta);
        }
コード例 #12
0
        public static void MyChar_Info_Req(LittleEndianAccessor lea, GhostClient gc)
        {
            lea.readInt();
            lea.readInt();
            string[] data     = lea.readAsciiString(0x100).Split(new string[] { " 0 " }, StringSplitOptions.None);
            string   username = data[1];
            string   password = data[2];

            gc.Account = new Account(gc);
            try
            {
                gc.Account.Load(username);

                if (password != gc.Account.Password)
                {
                    // -10
                }
                else if (gc.Account.LoggedIn > 0)
                {
                    // -2
                }
                else
                {
                    gc.Account.Characters = new List <Character>();
                    foreach (dynamic datum in new Datums("Characters").PopulateWith("id", "accountId = '{0}' && worldId = '{1}'", gc.Account.ID, gc.World.ID))
                    {
                        Character character = new Character(datum.id, gc);
                        character.Load(false);
                        gc.Account.Characters.Add(character);
                    }
                    gc.SendPacket(net.Packet.Chars.MyChar_Info_Ack(gc, gc.Account.Characters));
                }
            }
            catch (Exception ee)
            {
                if (ee.Message.Equals("account does not"))
                {
                    // -1
                }
                else
                {
                    Log.Error(ee.ToString());
                }
            }
        }
コード例 #13
0
        public static void handlerPacket(ReceiveOperationCode.Game recvops, LittleEndianAccessor lea, GhostClient gc)
        {
            switch (recvops)
            {
            case ReceiveOperationCode.Game.CHARACTER_SELECT:
                break;

            default:
                Console.WriteLine("未知Field Receive Operation Code {0}", recvops.ToString());
                break;
            }
        }
コード例 #14
0
        public static void handlerPacket(ReceiveOperationCode.Chars recvops, LittleEndianAccessor lea, GhostClient gc)
        {
            switch (recvops)
            {
            case ReceiveOperationCode.Chars.MYCHAR_INFO_REQ:
                net.handling.Chars.MyChar_Info_Req(lea, gc);
                break;

            case ReceiveOperationCode.Chars.CREATE_MYCHAR_REQ:
                net.handling.Chars.Create_MyChar_Req(lea, gc);
                break;

            case ReceiveOperationCode.Chars.CHECK_SAMENAME_REQ:
                net.handling.Chars.Check_SameName_Req(lea, gc);
                break;

            case ReceiveOperationCode.Chars.DELETE_MYCHAR_REQ:
                net.handling.Chars.Delete_MyChar_Req(lea, gc);
                break;

            default:
                Console.WriteLine("未知Chars Receive Operation Code {0}", recvops.ToString());
                break;
            }
        }
コード例 #15
0
        public static void handlerPacket(ReceiveOperationCode.Login recvops, LittleEndianAccessor lea, GhostClient gc)
        {
            switch (recvops)
            {
            case ReceiveOperationCode.Login.LOGIN_REQ:
                net.handling.Login.Login_Req(lea, gc);
                break;

            case ReceiveOperationCode.Login.SERVERLIST_REQ:
                net.handling.Login.ServerList_Req(lea, gc);
                break;

            case ReceiveOperationCode.Login.GAME_REQ:
                net.handling.Login.Game_Req(lea, gc);
                break;

            default:
                Console.WriteLine("未知Login Receive Operation Code {0}", recvops.ToString());
                break;
            }
        }
コード例 #16
0
ファイル: Login.cs プロジェクト: xDragonZ/GhostServer
 public static void Game_Req(LittleEndianAccessor lea, GhostClient gc)
 {
     gc.SendPacket(net.Packet.Login.Game_Ack(gc, 0));
 }
コード例 #17
0
ファイル: Login.cs プロジェクト: xDragonZ/GhostServer
 public static void ServerList_Req(LittleEndianAccessor lea, GhostClient gc)
 {
     gc.SendPacket(net.Packet.Login.ServerList_Ack(0, new int[] { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));
 }
コード例 #18
0
        public static void Create_MyChar_Req(LittleEndianAccessor lea, GhostClient gc)
        {
            lea.readInt();
            lea.readInt();
            string name   = lea.readAsciiString(20);
            int    gender = lea.readByte();
            int    unk1   = lea.readByte();
            int    unk2   = lea.readByte();
            int    unk3   = lea.readByte();
            int    eyes   = lea.readInt();
            int    hair   = lea.readInt();
            int    weapon = lea.readInt();
            int    armor  = lea.readInt();

            Character chr = new Character();

            chr.AccountID = gc.Account.ID;
            chr.WorldID   = gc.World.ID;
            chr.Name      = name;
            chr.Title     = "江湖人";
            chr.Level     = 1;
            chr.Class     = 0;
            chr.ClassLV   = 0xFF;
            chr.Gender    = (byte)gender;
            chr.Eyes      = eyes;
            chr.Hair      = hair;
            chr.Str       = 3;
            chr.Dex       = 3;
            chr.Vit       = 3;
            chr.Int       = 3;
            chr.Hp        = 31;
            chr.MaxHp     = 31;
            chr.Sp        = 15;
            chr.MaxSp     = 15;

            chr.Items.Add(new Item(weapon, (byte)ItemTypeConstants.EquipType.Weapon));
            chr.Items.Add(new Item(armor, (byte)ItemTypeConstants.EquipType.Dress));

            chr.Save();

            int pos;

            if ((gc.Account.Characters.Count + 1) <= 4)
            {
                gc.Account.Characters.Add(chr);
                pos = (gc.Account.Characters.Count << 8) + 1;
            }
            else if (Database.Exists("Characters", "name = '{0}'", name))
            {
                pos = -1;
            }
            else if ((gc.Account.Characters.Count + 1) > 4)
            {
                pos = -2;
            }
            else
            {
                pos = 0;
            }
            gc.SendPacket(net.Packet.Chars.Create_MyChar_Ack(pos));
        }