示例#1
0
        public void Battle(BattleLobby lobby)
        {
            int battleId = _user.Battle(lobby);

            _response.Status  = "200 OK\n";
            _response.Message = $"Your BattleId is:{battleId}\nPlease Watch the Log, when the Battle is finished";
        }
示例#2
0
        public void BattleLog(BattleLobby lobby)
        {
            var    definitionDelDeal = new { BATTLEID = "" };
            var    sCardId           = JsonConvert.DeserializeAnonymousType(_request.Message, definitionDelDeal);
            int    battleId          = Int32.Parse(sCardId.BATTLEID);
            string battleLog         = _user.BattleLog(lobby, battleId);

            if (battleLog.Length <= 50)
            {
                _response.Status  = "102 Processing\n";
                _response.Message = "Daten werden verarbeitet";
            }
            else
            {
                _response.Status  = "200 OK\n";
                _response.Message = $"{battleLog}";
            }
        }
示例#3
0
文件: Program.cs 项目: Raphiiee/MTCG
        static void Main(string[] args)
        {
            BattleLobby lobby = new BattleLobby();

            Thread t = new Thread(delegate()
            {
                // replace the IP with your system IP Address...
                Server myserver = new Server("127.0.0.1", 10001);
            });

            t.Start();

            Console.WriteLine("Server Started...!");

            while (true)
            {
                lobby.Start();
                //Thread.Sleep(250);
            }
        }
示例#4
0
        public void HandleDevice(Object obj)
        {
            TcpClient client = (TcpClient)obj;
            var       stream = client.GetStream();
            string    data   = null;

            Byte[]      bytes = new Byte[300000];
            int         i;
            DataHandler tcp    = new DataHandler();
            BattleLobby _lobby = new BattleLobby();

            try
            {
                while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                {
                    // Translate data bytes to a ASCII string.
                    data = Encoding.ASCII.GetString(bytes, 0, i);
                    data = data.ToUpper();
                    Console.WriteLine($"{Thread.CurrentThread.ManagedThreadId}: *******Received*******");
                    //Console.WriteLine("Received: {0}", data);

                    // Process the data sent by the client.


                    tcp.GetData(data);

                    if (tcp.GetPath() == AllowedPaths.Users && tcp.GetMethod() == AllowedMethods.POST)
                    {
                        tcp.Login();
                    }
                    else if (tcp.AuthorizationHeader())
                    {
                        if (tcp.AuthorizeClient())
                        {
                            if (tcp.GetPath() == AllowedPaths.Logout && tcp.GetMethod() == AllowedMethods.POST)
                            {
                                tcp.Logout();
                            }
                            else if (tcp.GetPath() == AllowedPaths.Stats && tcp.GetMethod() == AllowedMethods.GET)
                            {
                                tcp.ShowStats();
                            }
                            else if (tcp.GetPath() == AllowedPaths.Score && tcp.GetMethod() == AllowedMethods.GET)
                            {
                                tcp.ShowLeaderBoard();
                            }
                            else if (tcp.GetPath() == AllowedPaths.TransactionsPackages && tcp.GetMethod() == AllowedMethods.GET)
                            {
                                tcp.ShowShop();
                            }
                            else if (tcp.GetPath() == AllowedPaths.TransactionsPackages && tcp.GetMethod() == AllowedMethods.POST)
                            {
                                tcp.BuyCardPack();
                            }
                            else if (tcp.GetPath() == AllowedPaths.Cards && tcp.GetMethod() == AllowedMethods.GET)
                            {
                                tcp.ShowAllCards();
                            }
                            else if (tcp.GetPath() == AllowedPaths.Deck && tcp.GetMethod() == AllowedMethods.GET)
                            {
                                tcp.ShowDeckCards();
                            }
                            else if (tcp.GetPath() == AllowedPaths.Deck && tcp.GetMethod() == AllowedMethods.PUT)
                            {
                                tcp.ChangeDeckCards();
                            }
                            else if (tcp.GetPath() == AllowedPaths.Battle && tcp.GetMethod() == AllowedMethods.GET)
                            {
                                tcp.Battle(_lobby);
                            }
                            else if (tcp.GetPath() == AllowedPaths.BattleLog && tcp.GetMethod() == AllowedMethods.GET)
                            {
                                tcp.BattleLog(_lobby);
                            }
                            else if (tcp.GetPath() == AllowedPaths.Tradings && tcp.GetMethod() == AllowedMethods.GET)
                            {
                                tcp.ShowTrades();
                            }
                            else if (tcp.GetPath() == AllowedPaths.Tradings && tcp.GetMethod() == AllowedMethods.POST)
                            {
                                tcp.TradeOrInsert();
                            }
                            else if (tcp.GetPath() == AllowedPaths.Tradings && tcp.GetMethod() == AllowedMethods.DELETE)
                            {
                                tcp.DeleteTradeDeal();
                            }
                            else if (tcp.GetPath() == AllowedPaths.WatchAds && tcp.GetMethod() == AllowedMethods.GET)
                            {
                                tcp.WatchAds();
                            }
                            else
                            {
                                tcp.WrongPath();
                            }
                        }
                    }
                    else
                    {
                        tcp.FalseCredentials();
                        Console.WriteLine("Falsche Login Sachen");
                    }

                    tcp.MakeHeader();

                    Byte[] reply = Encoding.ASCII.GetBytes(tcp.GetHeader());
                    stream.Write(reply, 0, reply.Length);
                    //writer.Write("\r\n");
                    stream.Flush();
                    Console.WriteLine($"{Thread.CurrentThread.ManagedThreadId}: *******Received*******");
                    Console.WriteLine($"{Thread.CurrentThread.ManagedThreadId}: -------  SENT  -------");
                    Console.WriteLine("Sent: {0}", tcp.GetHeader());
                    Console.WriteLine($"{Thread.CurrentThread.ManagedThreadId}: -------  SENT  -------");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
                client.Close();
            }
        }
示例#5
0
文件: User.cs 项目: Raphiiee/MTCG
 public string BattleLog(BattleLobby lobby, int battleId)
 {
     return(lobby.ReadLog(battleId));
 }
示例#6
0
文件: User.cs 项目: Raphiiee/MTCG
        public int Battle(BattleLobby lobby)
        {
            int battleId = lobby.AddPlayer(Username);

            return(battleId);
        }