コード例 #1
0
        public static MatchResponse GetDominectMatch(GameCom.GameComClient client, uint width, uint height, string userToken)
        {
            var cancellationToken = new System.Threading.CancellationToken();

            cancellationToken.Register(() => Console.WriteLine("Request cancelled!"));
            var mmParam = new MatchmakingParameter();

            mmParam.RandomIsDefault = new Nothing();

            var request = new MatchRequest()
            {
                UserToken                = userToken,
                GameToken                = "dom",
                MatchmakingParameters    = mmParam,
                TimeoutSuggestionSeconds = 400,
                DomGameParameters        = new GameParameter()
                {
                    BoardWidth  = width,
                    BoardHeight = height
                }
            };

            var reply = client.NewMatch(request, null, DateTime.UtcNow.AddMinutes(1d), cancellationToken);

            return(reply);
        }
コード例 #2
0
 public DominectGame(GameCom.GameComClient client, string matchToken, string userToken)
 {
     this.client  = client;
     this.matchID = new MatchIDPacket()
     {
         MatchToken = matchToken, UserToken = userToken
     };
     this.rnd = new Random(); // TODO: Seed?
 }
コード例 #3
0
        public static string GetUserToken(GameCom.GameComClient client)
        {
            var cancellationToken = new System.Threading.CancellationToken();

            cancellationToken.Register(() => Console.WriteLine("Request cancelled!"));
            var reply = client.GetUserToken(auth, null, null, cancellationToken);

            return(reply.UserToken);
        }
コード例 #4
0
        public static SetPseudonymResponse.Types.ErrorCode SetPseudonym(GameCom.GameComClient client, string pseudonym)
        {
            var cancellationToken = new System.Threading.CancellationToken();

            cancellationToken.Register(() => Console.WriteLine("Pseudonym request cancelled!"));
            var request = new SetPseudonymRequest()
            {
                Auth      = auth,
                Pseudonym = pseudonym
            };
            var reply = client.SetGroupPseudonym(request, null, null, cancellationToken);

            return(reply.ErrorCode);
        }
コード例 #5
0
        public static void RegisterGroup(GameCom.GameComClient client)
        {
            var cancellationToken = new System.Threading.CancellationToken();

            cancellationToken.Register(() => Console.WriteLine("Request cancelled!"));
            var reply = client.GroupRegistration(new GroupRegistrationRequest()
            {
                Auth       = auth,
                MatrNumber = { matrNr }
            }, null, null, cancellationToken);

            switch (reply.ErrorCode)
            {
            case GroupRegistrationResponse.Types.ErrorCode.Ok:
                Console.WriteLine("OK:" + reply.ToString());
                break;

            default:
                Console.WriteLine("Error: " + reply.ErrorCode.ToString());
                break;
            }
        }
コード例 #6
0
        public static void RegisterMe(GameCom.GameComClient client)
        {
            var cancellationToken = new System.Threading.CancellationToken();

            cancellationToken.Register(() => Console.WriteLine("Request cancelled!"));
            var reply = client.UserRegistration(new UserRegistrationRequest()
            {
                Fullname   = fullname,
                MatrNumber = matrNr,
                Email      = email,
                Secret     = secret
            }, null, null, cancellationToken);

            switch (reply.ErrorCode)
            {
            case UserRegistrationResponse.Types.ErrorCode.Ok:
                Console.WriteLine("OK:" + reply.ToString());
                break;

            default:
                Console.WriteLine("Error: " + reply.ErrorCode.ToString());
                break;
            }
        }
コード例 #7
0
        public static void Main(string[] args)
        {
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

            var uri     = new Uri(gameserverIP);
            var channel = GrpcChannel.ForAddress(uri);
            var client  = new GameCom.GameComClient(channel);

            //RegisterMe(client);
            //RegisterGroup(client);
            string userToken = File.ReadLines("usertoken.txt").First(); //GetUserToken(client);

            if (userToken.Length == 0)
            {
                throw new Exception("Failed to get user token!");
            }

            Console.WriteLine("UserToken: " + userToken);

            /*
             * var error = SetPseudonym(client, "Potion Seller");
             * if(error == SetPseudonymResponse.Types.ErrorCode.Ok)
             * {
             *  Console.WriteLine("Pseudonym set!");
             * }
             * else
             * {
             *  Console.WriteLine("Error setting Pseudonym: " + error);
             * }
             */

            //ManualPlay(15, 15, 3); // TODO: comment out and turn playing on again


            bool playing     = true;
            int  gamesPlayed = 0;
            int  wins        = 0;
            int  aborted     = 0;
            bool manualMode  = false;

            while (playing && gamesPlayed < 10)
            {
                var match = GetDominectMatch(client, 10, 10, userToken);

                var game = new DominectGame(client, match.MatchToken, userToken);
                game.Start(match.BeginningPlayer);
                if (game.MatchAborted)
                {
                    aborted++;
                }
                else if (game.Status == GameStatus.MatchWon)
                {
                    wins++;
                }
                gamesPlayed++;
                Console.WriteLine("Games played: " + gamesPlayed + " - Wins/Aborted: " + wins + "/" + aborted);

                if (manualMode || game.CriticalError)
                {
                    Console.Write("Continue? (y|n) ");
                    var input = Console.ReadKey();
                    if (input.Key == ConsoleKey.Y)
                    {
                        Console.WriteLine();
                        continue;
                    }
                    else
                    {
                        Console.WriteLine("Goodbye!");
                        break;
                    }
                }
            }


            //File.WriteAllText("usertoken.txt", userToken);
        }