Esempio n. 1
0
        public Task <bool> JoinGame(DataGameViewModel game, IPAddress host, int port, string username, string password, bool spectate)
        {
            var user = new User(Guid.NewGuid().ToString(), username);

            var hostedGame = new HostedGame()
            {
                Id           = Guid.NewGuid(),
                GameId       = game.Id,
                GameName     = game.Name,
                OctgnVersion = Const.OctgnVersion.ToString(),
                GameVersion  = game.Version.ToString(),
                HostAddress  = $"{host}:{port}",
                Password     = password,
                DateCreated  = DateTime.UtcNow
            };

            DebugValidate(hostedGame, false);

            var args = "-j ";

            if (CommandLineHandler.Instance.DevMode)
            {
                args += "-x ";
            }

            args += $"-u \"{username}\" ";
            if (spectate)
            {
                args += "-s ";
            }

            args += "-k \"" + HostedGame.Serialize(hostedGame) + "\"";

            return(LaunchJodsEngine(args));
        }
Esempio n. 2
0
        void Connect(DataGameViewModel game, string userhost, string userport, string password)
        {
            Successful = false;
            IPAddress host = null;
            int       port = -1;

            this.ValidateFields(game, userhost, userport, password, out host, out port);

            Program.Client = new ClientSocket(host, port);
            Program.Client.Connect();
            Successful = true;
        }
Esempio n. 3
0
        void Connect(string username, DataGameViewModel game, string userhost, string userport, string password)
        {
            Successful = false;
            IPAddress host = null;
            int       port = -1;

            this.ValidateFields(username, game, userhost, userport, password, out host, out port);

            Program.IsHost     = false;
            Program.GameEngine = new Octgn.GameEngine(game.GetGame(), username, Spectator, password, true);

            Program.Client = new ClientSocket(host, port);
            Program.Client.Connect();
            Successful = true;
        }
Esempio n. 4
0
        void ValidateFields(string username, DataGameViewModel game, string host, string port, string password, out IPAddress ip, out int conPort)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentException("Username can't be empty");
            }
            if (string.IsNullOrWhiteSpace(host))
            {
                throw new ArgumentException("You must enter a host name/ip");
            }
            if (string.IsNullOrWhiteSpace(port))
            {
                throw new ArgumentException("You must enter a port number.");
            }

            if (game == null)
            {
                throw new ArgumentException("You must select a game");
            }

            // validate host/ip
            try
            {
                ip = Dns.GetHostAddresses(host)
                     .First(x => x.AddressFamily == AddressFamily.InterNetwork);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                throw new ArgumentException("Ip/Host name is invalid, or unreachable");
            }

            conPort = -1;

            if (!int.TryParse(port, out conPort))
            {
                throw new ArgumentException("Port number is invalid");
            }
            if (conPort <= 0 || conPort >= Int16.MaxValue)
            {
                throw new ArgumentException("Port number is invalid");
            }
        }