예제 #1
0
        void StartLocalGame(DataNew.Entities.Game game, string name, string password)
        {
            var hs = new HostedGame(HostPort, game.Id, game.Version, game.Name,game.IconUrl, name, null, new Skylabs.Lobby.User(Prefs.Nickname + "@" + AppConfig.ChatServerPath),true, true);
            if (!hs.StartProcess())
            {
                throw new UserMessageException("Cannot start local game. You may be missing a file.");
            }
            Program.LobbyClient.CurrentHostedGamePort = HostPort;
            Program.GameSettings.UseTwoSidedTable = HostGame.UseTwoSidedTable;
            Program.IsHost = true;
            Program.GameEngine = new GameEngine(game, Prefs.Nickname, false,password,true);

            var ip = IPAddress.Parse("127.0.0.1");

            for (var i = 0; i < 5; i++)
            {
                try
                {
                    Program.Client = new Octgn.Networking.ClientSocket(ip, HostPort);
                    Program.Client.Connect();
                    return;
                }
                catch (Exception e)
                {
                    Log.Warn("Start local game error", e);
                    if (i == 4) throw;
                }
                Thread.Sleep(2000);
            }
            throw new UserMessageException("Cannot start local game. You may be missing a file.");
        }
예제 #2
0
        void StartLocalGame(DataNew.Entities.Game game, string name, string password)
        {
            var hs = new HostedGame(HostPort, game.Id, game.Version, game.Name, name, null, new User(Prefs.Nickname + "@" + AppConfig.ChatServerPath), true);

            if (!hs.StartProcess())
            {
                throw new UserMessageException("Cannot start local game. You may be missing a file.");
            }
            Program.LobbyClient.CurrentHostedGamePort = HostPort;
            Program.GameSettings.UseTwoSidedTable     = true;
            Program.GameEngine = new GameEngine(game, Prefs.Nickname, true);
            Program.IsHost     = true;

            var ip = IPAddress.Parse("127.0.0.1");

            for (var i = 0; i < 5; i++)
            {
                try
                {
                    Program.Client = new Octgn.Networking.Client(ip, HostPort);
                    Program.Client.Connect();
                    return;
                }
                catch (Exception e)
                {
                    Log.Warn("Start local game error", e);
                    if (i == 4)
                    {
                        throw;
                    }
                }
                Thread.Sleep(2000);
            }
            throw new UserMessageException("Cannot start local game. You may be missing a file.");
        }
예제 #3
0
        void StartLocalGame(Data.Game game, string name, string password)
        {
            var hostport = new Random().Next(5000, 6000);

            while (!Networking.IsPortAvailable(hostport))
            {
                hostport++;
            }
            var hs = new HostedGame(hostport, game.Id, game.Version, game.Name, name, Password, new User(Username + "@" + Program.ChatServerPath), true);

            if (!hs.StartProcess())
            {
                throw new UserMessageException("Cannot start local game. You may be missing a file.");
            }
            Prefs.Nickname = Username;
            Program.LobbyClient.CurrentHostedGamePort = hostport;
            Program.GameSettings.UseTwoSidedTable     = true;
            Program.Game   = new Game(GameDef.FromO8G(game.FullPath), Username, true);
            Program.IsHost = true;

            var ip = IPAddress.Parse("127.0.0.1");

            Program.Client = new Client(ip, hostport);
            Program.Client.Connect();
            SuccessfulHost = true;
        }
예제 #4
0
        public static int HostGame(Guid g, Version v, string name, string pass, NewUser u)
        {
            Logger.PreLock();
            Locker.EnterWriteLock();//Enter Lock
            Logger.InLock();
            while (Games.ContainsKey(_currentHostPort) || !Networking.IsPortAvailable(_currentHostPort))
            {
                _currentHostPort++;
                if (_currentHostPort >= 20000)
                {
                    _currentHostPort = 10000;
                }
            }
            var hs = new HostedGame(_currentHostPort, g, v, name, pass, u);

            hs.HostedGameDone += HostedGameExited;
            if (hs.StartProcess())
            {
                Games.Add(_currentHostPort, hs);
                _totalHostedGames++;
                Locker.ExitWriteLock();//Exit Lock
                Logger.EndLock();
                return(_currentHostPort);
            }
            hs.HostedGameDone -= HostedGameExited;
            Locker.ExitWriteLock();//Exit Lock
            Logger.EndLock();
            return(-1);
        }
예제 #5
0
        private void GOnOnGameClick(object sender, EventArgs eventArgs)
        {
            var hg = sender as Octgn.Data.Game;

            if (hg == null || Program.PlayWindow != null)
            {
                Program.LauncherWindow.Navigate(new Login());
                return;
            }
            var hostport = 5000;

            while (!Skylabs.Lobby.Networking.IsPortAvailable(hostport))
            {
                hostport++;
            }
            var hs = new HostedGame(hostport, hg.Id, hg.Version, "LocalGame", "", null, true);

            hs.HostedGameDone += hs_HostedGameDone;
            if (!hs.StartProcess())
            {
                hs.HostedGameDone -= hs_HostedGameDone;
                Program.LauncherWindow.Navigate(new Login());
                return;
            }

            Program.IsHost = true;
            Data.Game theGame =
                Program.GamesRepository.Games.FirstOrDefault(g => g.Id == hg.Id);
            if (theGame == null)
            {
                return;
            }
            Program.Game = new Game(GameDef.FromO8G(theGame.FullPath), true);

            var       ad = new IPAddress[1];
            IPAddress ip = IPAddress.Parse("127.0.0.1");

            if (ad.Length <= 0)
            {
                return;
            }
            try
            {
                Program.Client = new Client(ip, hostport);
                Program.Client.Connect();
                Dispatcher.Invoke(new Action(() => Program.LauncherWindow.NavigationService.Navigate(new StartGame(true)
                {
                    Width = 400
                })));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
        }
예제 #6
0
        void StartLocalGame(DataNew.Entities.Game game, string name, string password)
        {
            var hostport = new Random().Next(5000, 6000);

            while (!Networking.IsPortAvailable(hostport))
            {
                hostport++;
            }
            var hs = new HostedGame(hostport, game.Id, game.Version, game.Name, name
                                    , Password, new User(Username + "@" + AppConfig.ChatServerPath), Specators, true);

            if (!hs.StartProcess())
            {
                throw new UserMessageException("Cannot start local game. You may be missing a file.");
            }
            Prefs.Nickname = Username;
            Program.LobbyClient.CurrentHostedGamePort = hostport;
            Program.GameEngine = new GameEngine(game, Username, false, password, true);
//            Program.GameSettings.UseTwoSidedTable = true;
            Program.CurrentOnlineGameName = name;
            Program.IsHost        = true;
            Program.IsMatchmaking = false;

            var ip = IPAddress.Parse("127.0.0.1");

            for (var i = 0; i < 5; i++)
            {
                try
                {
                    Program.Client = new ClientSocket(ip, hostport);
                    Program.Client.Connect();
                    SuccessfulHost = true;
                    return;
                }
                catch (Exception e)
                {
                    Log.Warn("Start local game error", e);
                    if (i == 4)
                    {
                        throw;
                    }
                }
                Thread.Sleep(2000);
            }
        }
예제 #7
0
        public void HostGame(HostGameRequest req, User u)
        {
            var bport = 21237;
            if (AppConfig.Instance.Test)
                bport = 21235;

            var game = new HostedGame(Ports.NextPort, req.GameGuid, req.GameVersion,
                req.GameName, req.Name, req.Password, u, false, true,req.RequestId,bport);

            if (game.StartProcess(true))
            {
                // Try to kill every other game this asshole started before this one.
                var others = GameListener.Games.Where(x => x.Username.Equals(u.UserName, StringComparison.InvariantCultureIgnoreCase))
                    .ToArray();
                foreach (var g in others)
                {
                    g.TryKillGame();
                }
            }
        }
예제 #8
0
파일: GameManager.cs 프로젝트: rerbes/OCTGN
        public Guid HostGame(HostGameRequest req, User u)
        {
            var bport = AppConfig.Instance.BroadcastPort;

            var game = new HostedGame(Ports.NextPort, req.GameGuid, req.GameVersion,
                req.GameName, req.Name, req.Password, u,req.Spectators ,false, true,req.RequestId,bport,req.SasVersion);

            if (game.StartProcess(true))
            {
                // Try to kill every other game this asshole started before this one.
                var others = GameListener.Games.Where(x => x.Username.Equals(u.UserName, StringComparison.InvariantCultureIgnoreCase))
                    .ToArray();
                foreach (var g in others)
                {
                    g.TryKillGame();
                }
                return game.Id;
            }
            return Guid.Empty;
        }
예제 #9
0
        public Guid HostGame(HostGameRequest req, User u)
        {
            var bport = AppConfig.Instance.BroadcastPort;

            var game = new HostedGame(Ports.NextPort, req.GameGuid, req.GameVersion,
                                      req.GameName, req.Name, req.Password, u, req.Spectators, false, true, req.RequestId, bport, req.SasVersion);

            if (game.StartProcess(true))
            {
                // Try to kill every other game this asshole started before this one.
                var others = GameListener.Games.Where(x => x.Username.Equals(u.UserName, StringComparison.InvariantCultureIgnoreCase))
                             .ToArray();
                foreach (var g in others)
                {
                    g.TryKillGame();
                }
                return(game.Id);
            }
            return(Guid.Empty);
        }
예제 #10
0
파일: Gaming.cs 프로젝트: karlnp/OCTGN
 public static int HostGame(Guid g, Version v, string name, string pass, User u, string gameName)
 {
     Locker.EnterWriteLock();//Enter Lock
     while (Games.ContainsKey(_currentHostPort) || !Networking.IsPortAvailable(_currentHostPort))
     {
         _currentHostPort++;
         if (_currentHostPort >= 20000)
             _currentHostPort = 10000;
     }
     var hs = new HostedGame(_currentHostPort, g, v, gameName, name, pass, u, true, true);
     hs.HostedGameDone += HostedGameExitedEventLauncher;
     if (hs.StartProcess())
     {
         Games.Add(_currentHostPort, hs);
         Locker.ExitWriteLock();//Exit Lock
         return _currentHostPort;
     }
     hs.HostedGameDone -= HostedGameExitedEventLauncher;
     Locker.ExitWriteLock();//Exit Lock
     return -1;
 }
예제 #11
0
        public static int HostGame(Guid g, Version v, string name, string pass, User u, string gameName)
        {
            Locker.EnterWriteLock();//Enter Lock
            while (Games.ContainsKey(_currentHostPort) || !Networking.IsPortAvailable(_currentHostPort))
            {
                _currentHostPort++;
                if (_currentHostPort >= 20000)
                {
                    _currentHostPort = 10000;
                }
            }
            var hs = new HostedGame(_currentHostPort, g, v, gameName, name, pass, u, true, true);

            hs.HostedGameDone += HostedGameExitedEventLauncher;
            if (hs.StartProcess())
            {
                Games.Add(_currentHostPort, hs);
                Locker.ExitWriteLock();//Exit Lock
                return(_currentHostPort);
            }
            hs.HostedGameDone -= HostedGameExitedEventLauncher;
            Locker.ExitWriteLock();//Exit Lock
            return(-1);
        }
예제 #12
0
        void StartLocalGame(DataNew.Entities.Game game, string name, string password)
        {
            var hostport = new Random().Next(5000,6000);
            while (!Networking.IsPortAvailable(hostport)) hostport++;
            var hs = new HostedGame(hostport, game.Id, game.Version, game.Name,game.IconUrl, name
                , Password, new User(Username + "@" + AppConfig.ChatServerPath),Specators, true);
            if (!hs.StartProcess())
            {
                throw new UserMessageException("Cannot start local game. You may be missing a file.");
            }
            Prefs.Nickname = Username;
            Program.LobbyClient.CurrentHostedGamePort = hostport;
            Program.GameEngine = new GameEngine(game, Username, false, password, true);
//            Program.GameSettings.UseTwoSidedTable = true;
            Program.CurrentOnlineGameName = name;
            Program.IsHost = true;
            Program.IsMatchmaking = false;

            var ip = IPAddress.Parse("127.0.0.1");

            for (var i = 0; i < 5; i++)
            {
                try
                {
                    Program.Client = new ClientSocket(ip, hostport);
                    Program.Client.Connect();
                    SuccessfulHost = true;
                    return;
                }
                catch (Exception e)
                {
                    Log.Warn("Start local game error",e);
                    if (i == 4) throw;
                }
                Thread.Sleep(2000);
            }
            
        }
예제 #13
0
파일: Login.xaml.cs 프로젝트: LordNat/OCTGN
        private void GOnOnGameClick(object sender, EventArgs eventArgs)
        {
            var hg = sender as Octgn.Data.Game;
                if (hg == null || Program.PlayWindow != null)
                {
                    Program.LauncherWindow.Navigate(new Login());
                    return;
                }
                var hostport = 5000;
                while (!Skylabs.Lobby.Networking.IsPortAvailable(hostport))
                    hostport++;
                var hs = new HostedGame(hostport, hg.Id, hg.Version, "LocalGame", "", null,true);
                hs.HostedGameDone += hs_HostedGameDone;
                if (!hs.StartProcess())
                {
                    hs.HostedGameDone -= hs_HostedGameDone;
                    Program.LauncherWindow.Navigate(new Login());
                    return;
                }

                Program.IsHost = true;
                Data.Game theGame =
                    Program.GamesRepository.Games.FirstOrDefault(g => g.Id == hg.Id);
                if (theGame == null) return;
                Program.Game = new Game(GameDef.FromO8G(theGame.FullPath),true);

                var ad = new IPAddress[1];
                IPAddress ip = IPAddress.Parse("127.0.0.1");

                if (ad.Length <= 0) return;
                try
                {
                    Program.Client = new Client(ip, hostport);
                    Program.Client.Connect();
                    Dispatcher.Invoke(new Action(() => Program.LauncherWindow.NavigationService.Navigate(new StartGame(true){Width = 400})));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    if (Debugger.IsAttached) Debugger.Break();
                }
        }
예제 #14
0
파일: Gaming.cs 프로젝트: voidbeast/OCTGN
 public static int HostGame(Guid g, Version v, string name, string pass, User u)
 {
     Logger.PreLock();
     Locker.EnterWriteLock();//Enter Lock
     Logger.InLock();
     while (Games.ContainsKey(_currentHostPort) || !Networking.IsPortAvailable(_currentHostPort))
     {
         _currentHostPort++;
         if (_currentHostPort >= 20000)
             _currentHostPort = 10000;
     }
     var hs = new HostedGame(_currentHostPort, g, v,"unknown", name, pass, u);
     hs.HostedGameDone += HostedGameExited;
     if (hs.StartProcess())
     {
         Games.Add(_currentHostPort, hs);
         _totalHostedGames++;
         Locker.ExitWriteLock();//Exit Lock
         Logger.EndLock();
         return _currentHostPort;
     }
     hs.HostedGameDone -= HostedGameExited;
     Locker.ExitWriteLock();//Exit Lock
     Logger.EndLock();
     return -1;
 }
예제 #15
0
        void StartLocalGame(Data.Game game, string name, string password)
        {
            var hostport = new Random().Next(5000,6000);
            while (!Networking.IsPortAvailable(hostport)) hostport++;
            var hs = new HostedGame(hostport, game.Id, game.Version, game.Name, name, Password, new User(Username + "@" + Program.ChatServerPath), true);
            if (!hs.StartProcess())
            {
                throw new UserMessageException("Cannot start local game. You may be missing a file.");
            }
            Prefs.Nickname = Username;
            Program.LobbyClient.CurrentHostedGamePort = hostport;
            Program.GameSettings.UseTwoSidedTable = true;
            Program.Game = new Game(GameDef.FromO8G(game.FullPath), Username, true);
            Program.IsHost = true;

            var ip = IPAddress.Parse("127.0.0.1");

            Program.Client = new Client(ip, hostport);
            Program.Client.Connect();
            SuccessfulHost = true;
        }
예제 #16
0
        public static int HostGame(Guid g,Version v, string name,string pass,User u)
        {
            Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "GamingLocker");
            lock(GamingLocker)
            {
                Logger.L(System.Reflection.MethodInfo.GetCurrentMethod().Name, "GamingLocker");
                while (Games.ContainsKey(_currentHostPort) || !Networking.IsPortAvailable(_currentHostPort))
                {
                    _currentHostPort++;
                    if (_currentHostPort >= 8000)
                        _currentHostPort = 5000;

                }
                HostedGame hs = new HostedGame(_currentHostPort,g,v,name,pass,u);
                hs.HostedGameDone += HostedGameExited;
                if (hs.StartProcess())
                {
                    Games.Add(_currentHostPort, hs);
                    _totalHostedGames++;
                    Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "GamingLocker");
                    return _currentHostPort;
                }
                else
                {
                    Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "GamingLocker");
                    hs.HostedGameDone -= HostedGameExited;
                    return -1;
                }
            }
        }