Ejemplo n.º 1
0
        private async Task Process(JoinBattleSuccess bat)
        {
            Battle battle;

            ExistingBattles.TryGetValue(bat.BattleID, out battle);
            if (battle != null)
            {
                battle.Users.Clear();
                foreach (var battleStatusUpdate in bat.Players)
                {
                    var ubs = new UserBattleStatus(battleStatusUpdate.Name, ExistingUsers.Get(battleStatusUpdate.Name));
                    ubs.UpdateWith(battleStatusUpdate);
                    battle.Users[battleStatusUpdate.Name] = ubs;
                }

                battle.Bots.Clear();
                foreach (var botStatusUpdate in bat.Bots)
                {
                    var ubs = new BotBattleStatus(botStatusUpdate.Name, botStatusUpdate.Owner, botStatusUpdate.AiLib);
                    ubs.UpdateWith(botStatusUpdate);
                    battle.Bots[botStatusUpdate.Name] = ubs;
                    BattleBotAdded(this, ubs);
                }

                MyBattle = battle;
                if (battle.FounderName == UserName)
                {
                    BattleOpened(this, battle);
                }
                BattleJoinSuccess(this, MyBattle);
            }
        }
Ejemplo n.º 2
0
        public async Task Process(UpdateBotStatus status)
        {
            var bat = MyBattle;

            if (bat != null)
            {
                BotBattleStatus ubs;
                bat.Bots.TryGetValue(status.Name, out ubs);
                if (ubs != null)
                {
                    ubs.UpdateWith(status);
                    BattleBotUpdated(this, ubs);
                }
                else
                {
                    var nubs = new BotBattleStatus(status.Name, status.Owner, status.AiLib);
                    nubs.UpdateWith(status);
                    bat.Bots[status.Name] = nubs;
                    BattleBotAdded(this, nubs);
                }
            }
        }
 private void Set_BotBattleStatus(string shortname,string ownerName, int? teamNumber, int? allyNumber,int? botColor, string version)
 {
     var aiLib = shortname;
     if (version != null) aiLib = aiLib + "|" + version; //splitter defined in Battle.cs/ScriptAddBot();
     var botNumber = Enumerable.Range(1, 9000).First(j => !Bots.Any(bt => bt.Name == "Bot_" + j));
     BotBattleStatus botStatus = new BotBattleStatus("Bot_" + botNumber,ownerName, aiLib);
     
     if (teamNumber.HasValue) botStatus.TeamNumber = teamNumber.Value;
     else botStatus.TeamNumber = Enumerable.Range(0, TasClient.MaxTeams - 1).FirstOrDefault(x => !allUser.Any(y => y.TeamNumber == x));
     
     if (allyNumber.HasValue) botStatus.TeamNumber = allyNumber.Value;
     else botStatus.AllyNumber = Enumerable.Range(0, TasClient.MaxAlliances - 1).FirstOrDefault(x => x != botStatus.AllyNumber);
     
     Bots.Add(botStatus);
     Refresh_PlayerBox();
 }
Ejemplo n.º 4
0
 static void ScriptAddBot(StringBuilder script, int aiNum, int teamNum, int userNum, BotBattleStatus status)
 {
     // AI
     var split = status.aiLib.Split('|');
     script.AppendFormat("  [AI{0}]\n", aiNum);
     script.AppendLine("  {");
     script.AppendFormat("    Name={0};\n", status.Name);
     script.AppendFormat("    ShortName={0};\n", split[0]);
     script.AppendFormat("    Version={0};\n", split.Length > 1 ? split[1] : ""); //having no value is better. Related file: ResolveSkirmishAIKey() at Spring/ExternalAI/IAILibraryManager.cpp 
     script.AppendFormat("    Team={0};\n", teamNum);
     script.AppendFormat("    Host={0};\n", userNum);
     script.AppendLine("    IsFromDemo=0;");
     script.AppendLine("    [Options]");
     script.AppendLine("    {");
     script.AppendLine("    }");
     script.AppendLine("  }\n");
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Generates script
        /// </summary>
        /// <param name="playersExport">list of players</param>
        /// <param name="localUser">myself</param>
        /// <param name="loopbackListenPort">listen port for autohost interface</param>
        /// <param name="zkSearchTag">hackish search tag</param>
        /// <param name="startSetup">structure with custom extra data</param>
        /// <returns></returns>
        public string GenerateScript(out List<UserBattleStatus> playersExport,
                                     User localUser,
                                     int loopbackListenPort,
                                     string zkSearchTag,
                                     SpringBattleStartSetup startSetup)
        {
            var previousCulture = Thread.CurrentThread.CurrentCulture;
            try
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

                playersExport = new List<UserBattleStatus>();
                var isHost = localUser.Name == Founder.Name;

                var myUbs = Users[localUser.Name];
                if (!isHost)
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("[GAME]");
                    sb.AppendLine("{");
                    sb.AppendFormat("HostIP={0};\n", Ip);
                    sb.AppendFormat("HostPort={0};\n", HostPort);
                    sb.AppendLine("IsHost=0;");
                    sb.AppendFormat("MyPlayerName={0};\n", localUser.Name);
                    if (myUbs != null)
                    {
                        if (myUbs.ScriptPassword != null) sb.AppendFormat("MyPasswd={0};\n", myUbs.ScriptPassword);
                    }
                    else
                    {
                        sb.AppendFormat("MyPasswd={0};\n", localUser.Name); // used for mid-game join .. if no userbattlestatus, use own name
                    }
                    sb.AppendLine("}");
                    return sb.ToString();
                }
                else
                {

                    var script = new StringBuilder();

                    script.AppendLine("[GAME]");
                    script.AppendLine("{");

                    script.AppendFormat("   ZkSearchTag={0};\n", zkSearchTag);
                    script.AppendFormat("  Mapname={0};\n", MapName);

                    script.AppendFormat("  StartPosType=2;\n");

                    script.AppendFormat("  GameType={0};\n", ModName);
                    script.AppendFormat("  ModHash=1;\n");
                    script.AppendFormat("  MapHash=1;\n");

                    script.AppendFormat("  AutohostPort={0};\n", loopbackListenPort);
                    script.AppendLine();
                    script.AppendFormat("  HostIP={0};\n", Ip);
                    script.AppendFormat("  HostPort={0};\n", HostPort);
                    script.AppendFormat("  SourcePort={0};\n", 8300);
                    script.AppendFormat("  IsHost=1;\n");
                    script.AppendLine();

                    //script.AppendFormat("  MyPlayerName={0};\n", localUser.Name);

                    List<UserBattleStatus> users;
                    List<BotBattleStatus> bots;

                    if (startSetup != null && startSetup.BalanceTeamsResult != null && startSetup.BalanceTeamsResult.Players != null)
                    {
                        // if there is a balance results as a part of start setup, use values from this (override lobby state)
                        users = Users.Values.ToList();
                        bots = new List<BotBattleStatus>(this.Bots.Values.Select(x => (BotBattleStatus)x.Clone()));
                        foreach (var p in startSetup.BalanceTeamsResult.Players)
                        {
                            var us = users.FirstOrDefault(x => x.Name == p.Name);
                            if (us == null)
                            {
                                us = new UserBattleStatus(p.Name, new User() { AccountID = p.LobbyID }, Password); // TODO this "password" use does not look right
                                users.Add(us);
                            }
                            us.TeamNumber = p.TeamID;
                            us.IsSpectator = p.IsSpectator;
                            us.AllyNumber = p.AllyID;

                        }
                        foreach (var p in startSetup.BalanceTeamsResult.Bots)
                        {
                            var bot = bots.FirstOrDefault(x => x.Name == p.BotName);
                            if (bot == null)
                            {
                                bot = new BotBattleStatus(p.BotName, p.Owner, p.BotAI);
                                bots.Add(bot);
                            }
                            bot.AllyNumber = bot.AllyNumber;
                            bot.TeamNumber = bot.TeamNumber;
                        }

                        foreach (var u in users.Where(x => !startSetup.BalanceTeamsResult.Players.Any(y => y.Name == x.Name)))
                        {
                            u.IsSpectator = true;
                        } // spec those not known at the time of balance
                    }
                    else
                    {
                        users = this.Users.Values.ToList();
                        bots = this.Bots.Values.ToList();
                    }


                    GeneratePlayerSection(playersExport, users, script, bots, Rectangles, ModOptions, localUser, startSetup);

                    return script.ToString();
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }
Ejemplo n.º 6
0
        static void ScriptAddBot(StringBuilder script, int aiNum, int teamNum, int userNum, BotBattleStatus status)
        {
            // AI
            var split = status.aiLib.Split('|');

            script.AppendFormat("  [AI{0}]\n", aiNum);
            script.AppendLine("  {");
            script.AppendFormat("    Name={0};\n", status.Name);
            script.AppendFormat("    ShortName={0};\n", split[0]);
            script.AppendFormat("    Version={0};\n", split.Length > 1 ? split[1] : ""); //having no value is better. Related file: ResolveSkirmishAIKey() at Spring/ExternalAI/IAILibraryManager.cpp
            script.AppendFormat("    Team={0};\n", teamNum);
            script.AppendFormat("    Host={0};\n", userNum);
            script.AppendLine("    IsFromDemo=0;");
            script.AppendLine("    [Options]");
            script.AppendLine("    {");
            script.AppendLine("    }");
            script.AppendLine("  }\n");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Generates script
        /// </summary>
        /// <param name="playersExport">list of players</param>
        /// <param name="localUser">myself</param>
        /// <param name="loopbackListenPort">listen port for autohost interface</param>
        /// <param name="zkSearchTag">hackish search tag</param>
        /// <param name="startSetup">structure with custom extra data</param>
        /// <returns></returns>
        public string GenerateScript(out List <UserBattleStatus> playersExport,
                                     User localUser,
                                     int loopbackListenPort,
                                     string zkSearchTag,
                                     SpringBattleStartSetup startSetup)
        {
            var previousCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

                playersExport = new List <UserBattleStatus>();
                var isHost = localUser.Name == Founder.Name;

                var myUbs = Users[localUser.Name];
                if (!isHost)
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("[GAME]");
                    sb.AppendLine("{");
                    sb.AppendFormat("HostIP={0};\n", Ip);
                    sb.AppendFormat("HostPort={0};\n", HostPort);
                    sb.AppendLine("IsHost=0;");
                    sb.AppendFormat("MyPlayerName={0};\n", localUser.Name);
                    if (myUbs != null)
                    {
                        if (myUbs.ScriptPassword != null)
                        {
                            sb.AppendFormat("MyPasswd={0};\n", myUbs.ScriptPassword);
                        }
                    }
                    else
                    {
                        sb.AppendFormat("MyPasswd={0};\n", localUser.Name); // used for mid-game join .. if no userbattlestatus, use own name
                    }
                    sb.AppendLine("}");
                    return(sb.ToString());
                }
                else
                {
                    var script = new StringBuilder();

                    script.AppendLine("[GAME]");
                    script.AppendLine("{");

                    script.AppendFormat("   ZkSearchTag={0};\n", zkSearchTag);
                    script.AppendFormat("  Mapname={0};\n", MapName);

                    script.AppendFormat("  StartPosType=2;\n");

                    script.AppendFormat("  GameType={0};\n", ModName);
                    script.AppendFormat("  ModHash=1;\n");
                    script.AppendFormat("  MapHash=1;\n");

                    script.AppendFormat("  AutohostPort={0};\n", loopbackListenPort);
                    script.AppendLine();
                    script.AppendFormat("  HostIP={0};\n", Ip);
                    script.AppendFormat("  HostPort={0};\n", HostPort);
                    script.AppendFormat("  SourcePort={0};\n", 8300);
                    script.AppendFormat("  IsHost=1;\n");
                    script.AppendLine();

                    //script.AppendFormat("  MyPlayerName={0};\n", localUser.Name);

                    List <UserBattleStatus> users;
                    List <BotBattleStatus>  bots;

                    if (startSetup != null && startSetup.BalanceTeamsResult != null && startSetup.BalanceTeamsResult.Players != null)
                    {
                        // if there is a balance results as a part of start setup, use values from this (override lobby state)
                        users = Users.Values.ToList();
                        bots  = new List <BotBattleStatus>(this.Bots.Values.Select(x => (BotBattleStatus)x.Clone()));
                        foreach (var p in startSetup.BalanceTeamsResult.Players)
                        {
                            var us = users.FirstOrDefault(x => x.Name == p.Name);
                            if (us == null)
                            {
                                us = new UserBattleStatus(p.Name, new User()
                                {
                                    AccountID = p.LobbyID
                                }, Password);                                                                      // TODO this "password" use does not look right
                                users.Add(us);
                            }
                            us.TeamNumber  = p.TeamID;
                            us.IsSpectator = p.IsSpectator;
                            us.AllyNumber  = p.AllyID;
                        }
                        foreach (var p in startSetup.BalanceTeamsResult.Bots)
                        {
                            var bot = bots.FirstOrDefault(x => x.Name == p.BotName);
                            if (bot == null)
                            {
                                bot = new BotBattleStatus(p.BotName, p.Owner, p.BotAI);
                                bots.Add(bot);
                            }
                            bot.AllyNumber = bot.AllyNumber;
                            bot.TeamNumber = bot.TeamNumber;
                        }

                        foreach (var u in users.Where(x => !startSetup.BalanceTeamsResult.Players.Any(y => y.Name == x.Name)))
                        {
                            u.IsSpectator = true;
                        } // spec those not known at the time of balance
                    }
                    else
                    {
                        users = this.Users.Values.ToList();
                        bots  = this.Bots.Values.ToList();
                    }


                    GeneratePlayerSection(playersExport, users, script, bots, Rectangles, ModOptions, localUser, startSetup);

                    return(script.ToString());
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }
Ejemplo n.º 8
0
        static void ScriptAddBot(StringBuilder script, int aiNum, int teamNum, int userNum, BotBattleStatus status)
        {
            // AI
            var split = status.aiLib.Split('|');

            script.AppendFormat("  [AI{0}]\n", aiNum);
            script.AppendLine("  {");
            script.AppendFormat("    ShortName={0};\n", split[0]);
            script.AppendFormat("    Version={0};\n", split.Length > 1 ? split[1] : "");
            script.AppendFormat("    Team={0};\n", teamNum);
            script.AppendFormat("    Host={0};\n", userNum);
            script.AppendLine("    IsFromDemo=0;");
            script.AppendLine("    [Options]");
            script.AppendLine("    {");
            script.AppendLine("    }");
            script.AppendLine("  }\n");
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Generates script
        /// </summary>
        /// <param name="playersExport">list of players</param>
        /// <param name="localUser">myself</param>
        /// <param name="loopbackListenPort">listen port for autohost interface</param>
        /// <param name="zkSearchTag">hackish search tag</param>
        /// <param name="startSetup">structure with custom extra data</param>
        /// <returns></returns>
        public string GenerateScript(out List <UserBattleStatus> playersExport,
                                     User localUser,
                                     int loopbackListenPort,
                                     string zkSearchTag,
                                     SpringBattleStartSetup startSetup)
        {
            var previousCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

                playersExport = new List <UserBattleStatus>();
                var isHost = localUser.Name == Founder.Name;
                var myUbs  = Users.Single(x => x.Name == localUser.Name);
                if (!isHost)
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("[GAME]");
                    sb.AppendLine("{");
                    sb.AppendFormat("HostIP={0};\n", Ip);
                    sb.AppendFormat("HostPort={0};\n", HostPort);
                    sb.AppendLine("IsHost=0;");
                    sb.AppendFormat("MyPlayerName={0};\n", localUser.Name);
                    if (myUbs.ScriptPassword != null)
                    {
                        sb.AppendFormat("MyPasswd={0};\n", myUbs.ScriptPassword);
                    }
                    sb.AppendLine("}");
                    return(sb.ToString());
                }
                else
                {
                    if (mod == null)
                    {
                        throw new ApplicationException("Mod not downloaded yet");
                    }

                    var script = new StringBuilder();

                    script.AppendLine("[GAME]");
                    script.AppendLine("{");

                    script.AppendFormat("   ZkSearchTag={0};\n", zkSearchTag);
                    script.AppendFormat("  Mapname={0};\n", MapName);

                    if (mod.IsMission)
                    {
                        script.AppendFormat("  StartPosType=3;\n");
                    }
                    else
                    {
                        if (Details.StartPos == BattleStartPos.Choose)
                        {
                            script.AppendFormat("  StartPosType=2;\n");
                        }
                        else
                        {
                            script.AppendFormat("  StartPosType=3;\n");  // workaround for random/fixed
                        }
                        // script.AppendFormat("  StartPosType={0};\n", (int)Details.StartPos);
                    }

                    script.AppendFormat("  GameType={0};\n", ModName);
                    if (ModHash.HasValue)
                    {
                        script.AppendFormat("  ModHash={0};\n", ModHash.Value != 0 ? (uint)ModHash.Value : 1);
                    }
                    // hack dont set to 1 when dedi srever is patched
                    if (MapHash.HasValue)
                    {
                        script.AppendFormat("  MapHash={0};\n", MapHash.Value != 0 ? (uint)MapHash.Value : 1);
                    }
                    script.AppendFormat("  AutohostPort={0};\n", loopbackListenPort);
                    script.AppendLine();
                    script.AppendFormat("  HostIP={0};\n", Ip);
                    script.AppendFormat("  HostPort={0};\n", HostPort);
                    script.AppendFormat("  SourcePort={0};\n", 8300);
                    script.AppendFormat("  IsHost=1;\n");
                    script.AppendLine();

                    //script.AppendFormat("  MyPlayerName={0};\n", localUser.Name);

                    var positions = map.Positions != null?map.Positions.ToList() : new List <StartPos>();

                    if (Details.StartPos == BattleStartPos.Random)
                    {
                        positions = positions.Shuffle();
                    }

                    List <UserBattleStatus> users;
                    List <BotBattleStatus>  bots;

                    if (startSetup != null && startSetup.BalanceTeamsResult != null && startSetup.BalanceTeamsResult.Players != null)
                    {
                        // if there is a balance results as a part of start setup, use values from this (override lobby state)
                        users = new List <UserBattleStatus>(this.Users.Select(x => x.Clone()));
                        bots  = new List <BotBattleStatus>(this.Bots.Select(x => (BotBattleStatus)x.Clone()));
                        foreach (var p in startSetup.BalanceTeamsResult.Players)
                        {
                            var us = users.FirstOrDefault(x => x.Name == p.Name);
                            if (us == null)
                            {
                                us = new UserBattleStatus(p.Name, new User()
                                {
                                    LobbyID = p.LobbyID
                                }, Password);
                                users.Add(us);
                            }
                            us.TeamNumber  = p.TeamID;
                            us.IsSpectator = p.IsSpectator;
                            us.AllyNumber  = p.AllyID;
                        }
                        foreach (var p in startSetup.BalanceTeamsResult.Bots)
                        {
                            var bot = bots.FirstOrDefault(x => x.Name == p.BotName);
                            if (bot == null)
                            {
                                bot = new BotBattleStatus(p.BotName, p.Owner, p.BotAI);
                                bots.Add(bot);
                            }
                            bot.AllyNumber = bot.AllyNumber;
                            bot.TeamNumber = bot.TeamNumber;
                        }

                        foreach (var u in users.Where(x => !startSetup.BalanceTeamsResult.Players.Any(y => y.Name == x.Name)))
                        {
                            u.IsSpectator = true;
                        } // spec those not known at the time of balance
                    }
                    else
                    {
                        users = this.Users;
                        bots  = this.Bots;
                    }


                    GeneratePlayerSection(playersExport, localUser, startSetup, users, script, positions, bots);

                    return(script.ToString());
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }