Exemplo n.º 1
0
        public static void StartGameService(IPAddress IP, GameSettings setting, int roomId, GameEndCallback callback, out int portNumber)
        {
            int totalNumberOfPlayers = setting.TotalPlayers;
            int timeOutSeconds = setting.TimeOutSeconds;
            #if DEBUG
            Trace.Listeners.Clear();

            TextWriterTraceListener twtl = new TextWriterTraceListener(Path.Combine(Directory.GetCurrentDirectory(), AppDomain.CurrentDomain.FriendlyName + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".txt"));
            twtl.Name = "TextLogger";
            twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;

            ConsoleTraceListener ctl = new ConsoleTraceListener(false);
            ctl.TraceOutputOptions = TraceOptions.DateTime;

            Trace.Listeners.Add(twtl);
            Trace.Listeners.Add(ctl);
            Trace.AutoFlush = true;
            Trace.WriteLine("Log starting");
            Trace.Listeners.Add(new ConsoleTraceListener());
            #endif
            Game game = new RoleGame();
            game.Settings = setting;
            Sanguosha.Core.Network.Server server;
            server = new Sanguosha.Core.Network.Server(game, totalNumberOfPlayers, IP);
            portNumber = server.IpPort;
            for (int i = 0; i < totalNumberOfPlayers; i++)
            {
                var player = new Player();
                player.Id = i;
                game.Players.Add(player);
                IUiProxy proxy;
                proxy = new ServerNetworkUiProxy(server, i);
                proxy.TimeOutSeconds = timeOutSeconds;
                proxy.HostPlayer = player;
                game.UiProxies.Add(player, proxy);
            }
            GlobalServerUiProxy pxy = new GlobalServerUiProxy(game, game.UiProxies);
            pxy.TimeOutSeconds = timeOutSeconds;
            game.GlobalProxy = pxy;
            game.NotificationProxy = new DummyNotificationProxy();
            foreach (var g in GameEngine.Expansions.Values)
            {
                game.LoadExpansion(g);
            }
            game.GameServer = server;
            var thread = new Thread(() => { game.Run(); callback(roomId); }) { IsBackground = true };
            thread.Start();
        }
Exemplo n.º 2
0
Arquivo: Game.cs Projeto: pxoylngx/sgs
 public Game()
 {
     cardSet = new List<Card>();
     originalCardSet = new List<Card>();
     triggers = new Dictionary<GameEvent, List<Trigger>>();
     decks = new DeckContainer();
     players = new List<Player>();
     cardHandlers = new Dictionary<string, CardHandler>();
     uiProxies = new Dictionary<Player, IUiProxy>();
     currentActingPlayer = null;
     triggersToRegister = new List<DelayedTriggerRegistration>();
     isDying = new Stack<Player>();
     handCardVisibility = new Dictionary<Player, List<Player>>();
     Settings = new GameSettings();
 }
Exemplo n.º 3
0
 public RoomOperationResult StartGame(LoginToken token)
 {
     if (VerifyClient(token))
     {
         if (!loggedInGuidToRoom.ContainsKey(token.token)) { return RoomOperationResult.Invalid; }
         int portNumber;
         var room = loggedInGuidToRoom[token.token];
         var total = room.Seats.Count(pl => pl.Account != null);
         var initiator = room.Seats.FirstOrDefault(pl => pl.Account == loggedInGuidToAccount[token.token]);
         if (room.State == RoomState.Gaming) return RoomOperationResult.Invalid;
         if (total <= 1) return RoomOperationResult.Invalid;
         if (initiator == null || initiator.State != SeatState.Host) return RoomOperationResult.Invalid;
         room.State = RoomState.Gaming;
         var gs = new GameSettings() { TimeOutSeconds = room.TimeOutSeconds, TotalPlayers = total, CheatEnabled = CheatEnabled };
         GameService.StartGameService(HostingIp, gs, room.Id, _OnGameEnds, out portNumber);
         _NotifyGameStart(loggedInGuidToRoom[token.token].Id, HostingIp, portNumber);
         return RoomOperationResult.Success;
     }
     return RoomOperationResult.Auth;
 }
Exemplo n.º 4
0
        public RoomOperationResult StartGame()
        {
            if (currentAccount == null) return RoomOperationResult.NotAutheticated;
            if (currentAccount.CurrentRoom == null) { return RoomOperationResult.Invalid; }
            int portNumber;
            var room = currentAccount.CurrentRoom;
            var total = room.Room.Seats.Count(pl => pl.Account != null);
            var initiator = room.Room.Seats.FirstOrDefault(pl => pl.Account == currentAccount.Account);
            if (room.Room.State == RoomState.Gaming) return RoomOperationResult.Invalid;
            if (total <= 1) return RoomOperationResult.Invalid;
            if (initiator == null || initiator.State != SeatState.Host) return RoomOperationResult.Invalid;
            if (room.Room.Seats.Any(cs => cs.Account != null && cs.State != SeatState.Host && cs.State != SeatState.GuestReady)) return RoomOperationResult.Invalid;
            lock (room.Room)
            {
                room.Room.State = RoomState.Gaming;
                foreach (var unready in room.Room.Seats)
                {
                    if (unready.State == SeatState.GuestReady) unready.State = SeatState.Gaming;
                }
                var gs = new GameSettings()
                {
                    TimeOutSeconds = room.Room.Settings.TimeOutSeconds,
                    TotalPlayers = total,
                    CheatEnabled = CheatEnabled,
                    DualHeroMode = room.Room.Settings.IsDualHeroMode,
                    NumHeroPicks = room.Room.Settings.NumHeroPicks,
                    NumberOfDefectors = room.Room.Settings.NumberOfDefectors == 2 ? 2 : 1,
                    GameType = room.Room.Settings.GameType,
                };

                // Load pakcages.
                if (gs.GameType == GameType.RoleGame)
                {
                    gs.PackagesEnabled.Add("Sanguosha.Expansions.BasicExpansion");
                    gs.PackagesEnabled.Add("Sanguosha.Expansions.BattleExpansion");
                    if ((room.Room.Settings.EnabledPackages & EnabledPackages.Wind) != 0) gs.PackagesEnabled.Add("Sanguosha.Expansions.WindExpansion");
                    if ((room.Room.Settings.EnabledPackages & EnabledPackages.Fire) != 0) gs.PackagesEnabled.Add("Sanguosha.Expansions.FireExpansion");
                    if ((room.Room.Settings.EnabledPackages & EnabledPackages.Woods) != 0) gs.PackagesEnabled.Add("Sanguosha.Expansions.WoodsExpansion");
                    if ((room.Room.Settings.EnabledPackages & EnabledPackages.Hills) != 0) gs.PackagesEnabled.Add("Sanguosha.Expansions.HillsExpansion");
                    if ((room.Room.Settings.EnabledPackages & EnabledPackages.SP) != 0)
                    {
                        gs.PackagesEnabled.Add("Sanguosha.Expansions.SpExpansion");
                        gs.PackagesEnabled.Add("Sanguosha.Expansions.StarSpExpansion");
                    }
                    if ((room.Room.Settings.EnabledPackages & EnabledPackages.OverKnightFame) != 0)
                    {
                        gs.PackagesEnabled.Add("Sanguosha.Expansions.OverKnightFame11Expansion");
                        gs.PackagesEnabled.Add("Sanguosha.Expansions.OverKnightFame12Expansion");
                        gs.PackagesEnabled.Add("Sanguosha.Expansions.OverKnightFame13Expansion");
                    }
                    if ((room.Room.Settings.EnabledPackages & EnabledPackages.Others) != 0)
                    {
                        gs.PackagesEnabled.Add("Sanguosha.Expansions.AssasinExpansion");
                    }
                }
                if (gs.GameType == GameType.Pk1v1)
                {
                    gs.PackagesEnabled.Add("Sanguosha.Expansions.Pk1v1Expansion");
                }

                foreach (var addconfig in room.Room.Seats)
                {
                    var account = addconfig.Account;
                    if (account != null)
                    {
                        account.LoginToken = new LoginToken() { TokenString = Guid.NewGuid() };
                        account.IsDead = false;
                        gs.Accounts.Add(account);
                    }
                }
                GameService.StartGameService(HostingIp, gs, room.Room.Id, _OnGameEnds, out portNumber);
                room.Room.IpAddress = HostingIp.ToString();
                room.Room.IpPort = portNumber;
                _NotifyGameStart(room.Room.Id, HostingIp, portNumber);
            }
            return RoomOperationResult.Success;
        }
Exemplo n.º 5
0
 public RoomOperationResult StartGame(LoginToken token)
 {
     if (VerifyClient(token))
     {
         if (!loggedInGuidToRoom.ContainsKey(token.token)) { return RoomOperationResult.Invalid; }
         int portNumber;
         var room = loggedInGuidToRoom[token.token];
         var total = room.Seats.Count(pl => pl.Account != null);
         var initiator = room.Seats.FirstOrDefault(pl => pl.Account == loggedInGuidToAccount[token.token]);
         if (room.State == RoomState.Gaming) return RoomOperationResult.Invalid;
         if (total <= 1) return RoomOperationResult.Invalid;
         if (initiator == null || initiator.State != SeatState.Host) return RoomOperationResult.Invalid;
         if (room.Seats.Any(cs => cs.Account != null && cs.State != SeatState.Host && cs.State != SeatState.GuestReady)) return RoomOperationResult.Invalid;
         room.State = RoomState.Gaming;
         foreach (var unready in room.Seats)
         {
             if (unready.State == SeatState.GuestReady) unready.State = SeatState.GuestTaken;
         }
         var gs = new GameSettings() { TimeOutSeconds = room.TimeOutSeconds, TotalPlayers = total, CheatEnabled = CheatEnabled };
         var config = new AccountConfiguration();
         config.AccountIds = new List<LoginToken>();
         config.Accounts = new List<Account>();
         foreach (var addconfig in room.Seats)
         {
             if (addconfig.Account != null)
             {
                 config.AccountIds.Add(new LoginToken() { token = loggedInAccountToGuid[addconfig.Account] });
                 config.Accounts.Add(addconfig.Account);
             }
         }
         GameService.StartGameService(HostingIp, gs, config, room.Id, _OnGameEnds, out portNumber);
         room.IpAddress = HostingIp.ToString();
         room.IpPort = portNumber;
         _NotifyGameStart(loggedInGuidToRoom[token.token].Id, HostingIp, portNumber);
         return RoomOperationResult.Success;
     }
     return RoomOperationResult.Auth;
 }