/// <summary>This method writes the type marker and string.</summary>
        internal void WriteAmf0AsObject(AsObject obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            AddAmf0Reference(obj);
            var anonymousObject = string.IsNullOrEmpty(obj.TypeName);

            WriteMarker(anonymousObject ? Amf0TypeMarkers.Object : Amf0TypeMarkers.TypedObject);
            if (!anonymousObject)
            {
                WriteUtfPrefixed(obj.TypeName);
            }

            foreach (var property in obj)
            {
                WriteUtfPrefixed(property.Key);
                WriteAmf0Item(property.Value);
            }

            // End of object denoted by zero-length field name, then end of object type marker
            // Field names are length-prefixed UTF8 strings, so [0 length string, end of object type marker]
            WriteUInt16(0);
            WriteMarker(Amf0TypeMarkers.ObjectEnd);
        }
Esempio n. 2
0
            void WriteAsObject(AsObject value)
            {
                CheckDebug.NotNull(value);
                ReferenceAdd(value);

                if (string.IsNullOrEmpty(value.TypeName))
                {
                    WriteMarker(Marker.Object);
                }
                else
                {
                    WriteMarker(Marker.TypedObject);
                    b.WriteUtfPrefixed(value.TypeName);
                }

                foreach (var property in value)
                {
                    b.WriteUtfPrefixed(property.Key);
                    WriteItem(property.Value);
                }

                // object end is marked with a zero-length field name, and an end of object marker.
                b.WriteUInt16(0);
                WriteMarker(Marker.ObjectEnd);
            }
Esempio n. 3
0
            AsObject ReadAsObject()
            {
                var asObject = new AsObject();

                refs.Add(asObject);
                asObject.Replace(ReadItems());

                return(asObject);
            }
Esempio n. 4
0
        internal void WriteAmf0AsObject(AsObject obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            this.AddAmf0Reference((object)obj);
            bool flag = string.IsNullOrEmpty(obj.TypeName);

            this.WriteMarker(flag ? Amf0TypeMarkers.Object : Amf0TypeMarkers.TypedObject);
            if (!flag)
            {
                this.WriteUtfPrefixed(obj.TypeName);
            }
            foreach (KeyValuePair <string, object> keyValuePair in obj)
            {
                this.WriteUtfPrefixed(keyValuePair.Key);
                this.WriteAmf0Item(keyValuePair.Value);
            }
            this.WriteUInt16((ushort)0);
            this.WriteMarker(Amf0TypeMarkers.ObjectEnd);
        }
Esempio n. 5
0
        private static async void RoomMessageHandler(object sender, object message)
        {
            //Our group already finished?
            if (System.IO.File.Exists("Logs/" + hostName + ".gfinished"))
            {
                System.Environment.Exit(0);
            }

            //Console.WriteLine(groupSplitted);
            try
            {
                if (((MessageReceivedEventArgs)message).Body is RtmpSharp.IO.AsObject)
                {
                    if (!groupSplitted)
                    {
                        return;
                    }

                    //Convert object
                    RtmpSharp.IO.AsObject asnObject = ((MessageReceivedEventArgs)message).Body as AsObject;

                    if (asnObject.TypeName == "com.riotgames.platform.gameinvite.contract.InvitationRequest" && Client.botType == "BOT")
                    {
                        String InvitationState = asnObject["invitationState"] as String;

                        if (InvitationState != "ACTIVE")
                        {
                            return;
                        }

                        String InvitationId = asnObject["invitationId"] as String;

                        //Join them :)!
                        try
                        {
                            Console.WriteLine("Accepting Invitation");
                            await RiotCalls.Accept(InvitationId);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("INVITATION: " + e.Message);
                            return;
                        }

                        return;
                    }

                    if (Client.botType == "HOST" || Client.botType == "HOST2")
                    {
                        RtmpSharp.IO.AsObject lobbyStatus = asnObject;

                        //Check if 5 Invitations got sent
                        RtmpSharp.IO.AMF3.ArrayCollection invitees = lobbyStatus["invitees"] as RtmpSharp.IO.AMF3.ArrayCollection;

                        //if (invitees.Count != 5)
                        //{
                        //    await InvitePlayers();
                        //}

                        //Check if 5 Players are in lobby
                        RtmpSharp.IO.AMF3.ArrayCollection members = lobbyStatus["members"] as RtmpSharp.IO.AMF3.ArrayCollection;

                        if (members.Count == 5)
                        {
                            //Wait and attach to queue
                            Thread.Sleep(1500);

                            MatchMakerParams matchParams = new MatchMakerParams();
                            matchParams.Languages     = null;
                            matchParams.BotDifficulty = "EASY";
                            matchParams.Team          = new List <int>();

                            for (int i = 0; i < members.Count; ++i)
                            {
                                RtmpSharp.IO.AsObject memberObj = members[i] as RtmpSharp.IO.AsObject;
                                //Console.WriteLine(memberObj["summonerId"]);
                                matchParams.Team.Add(Convert.ToInt32(memberObj["summonerId"]));
                            }

                            matchParams.QueueIds     = new int[] { 25 };
                            matchParams.InvitationId = lobbyStatus["invitationId"] as String;

                            await RiotCalls.AttachTeamToQueue(matchParams);

                            Console.WriteLine("Attached to Queue");
                        }
                    }
                }
                else if (message.GetType() == typeof(GameDTO) || ((MessageReceivedEventArgs)message).Body.GetType() == typeof(GameDTO))
                {
                    GameDTO dto = null;

                    try
                    {
                        if (message.GetType() == typeof(GameDTO))
                        {
                            dto = message as GameDTO;
                        }
                        else
                        {
                            dto = ((MessageReceivedEventArgs)message).Body as GameDTO;
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Ignoring => Convert (object to GameDTO)");
                        return;
                    }

                    //Console.WriteLine(dto.GameState + ":" + groupSplitted);

                    //Game Popup?
                    if (dto.GameState == "JOINING_CHAMP_SELECT" && !acceptedGame)
                    {
                        try
                        {
                            await RiotCalls.AcceptPoppedGame(true);
                        }
                        catch (Exception e)
                        { }

                        acceptedGame = true;
                        return;
                    }

                    //Host left room? follow him!
                    //if (Client.botType == "BOT" && dto.GameState == "TEAM_SELECT")
                    //{
                    //    bool leaveRoom = false;

                    //    if (groupSplitted)
                    //    {
                    //        if (lvlGroupType == "ZERO")
                    //        {
                    //            if (dto.OwnerSummary.SummonerInternalName != hostName)
                    //                leaveRoom = true;
                    //        }

                    //        if (lvlGroupType == "ONE")
                    //        {
                    //            if (dto.OwnerSummary.SummonerInternalName != hostNameTwo)
                    //                leaveRoom = true;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        if (dto.OwnerSummary.SummonerInternalName != hostName)
                    //            leaveRoom = true;
                    //    }

                    //    if (leaveRoom)
                    //    {
                    //        Console.WriteLine("Host left the game, follow him!");
                    //        restart();
                    //    }
                    //}

                    if (dto.GameState == "TEAM_SELECT" && !groupSplitted)
                    {
                        List <Participant> AllParticipants = new List <Participant>(dto.TeamOne.ToArray());
                        AllParticipants.AddRange(dto.TeamTwo);

                        //Console.WriteLine("Player joined the game! " + AllParticipants.Count.ToString() + "/10");
                        gameState = "TEAM_SELECT";

                        if (Client.botType == "HOST")
                        {
                            int playerRoomCount = 10;

                            if (AllParticipants.Count == playerRoomCount) // 10/5 Players joined?
                            {
                                Thread.Sleep(1500);

                                await RiotCalls.StartChampionSelection(dto.Id, dto.OptimisticLock);

                                Console.WriteLine("Room started!");
                                gameState = "CHAMP_SELECT";
                            }
                        }
                    }

                    //Something failed
                    if (dto.GameState.Contains("FAILED"))
                    {
                        Console.WriteLine("FATAL: " + dto.GameState);
                        restart();
                    }

                    //Roomstate changed
                    if (dto.GameState == "TEAM_SELECT" && gameState == "CHAMP_SELECT")
                    {
                        gameState = "TEAM_SELECT";
                        Console.WriteLine("Unknown player left the room!");
                        //restart();
                    }

                    //Selecting Champion etc.
                    if (dto.GameState == "CHAMP_SELECT" || dto.GameState == "PRE_CHAMP_SELECT")
                    {
                        inInviteLobby = false;
                        gameState     = "CHAMP_SELECT";

                        if (!Client.selectedChampion)
                        {
                            Client.selectedChampion = true;
                            gameState = "CHAMP_SELECT";

                            //Signal to the server we are in champion select
                            try
                            {
                                await RiotCalls.SetClientReceivedGameMessage(dto.Id, "CHAMP_SELECT_CLIENT");

                                globalDto = dto;
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Ignoring => " + e.Message);
                            }

                            try
                            {
                                await RiotCalls.ChampionSelectCompleted();

                                Console.WriteLine("Selected Champion and Locked");

                                //await RiotCalls.ChampionSelectCompleted();
                                //Console.WriteLine("[2]Selected Champion and Locked");
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Locking in error: " + e.Message);
                            }
                        }
                    }

                    //Game ended
                    if (dto.GameState == "TERMINATED" || dto.GameState == "TERMINATED_IN_ERROR")
                    {
                        gameStarted  = false;
                        acceptedGame = false;
                        gameState    = "LOBBY";

                        AllSummonerData summonerData = null;
                        summonerData = await RiotCalls.GetAllSummonerDataByAccount(Client.PlayerSession.AccountSummary.AccountId);

                        lastSummonerData = summonerData;

                        if (Client.botType == "HOST")
                        {
                            try
                            {
                                System.IO.File.Delete("Logs/Rooms/" + hostName + ".roomID");
                            }
                            catch (Exception elol)
                            { }
                        }

                        Console.WriteLine(DateTime.Now.ToString("HH:mm:ss tt") + " end");
                        Console.WriteLine("Level " + summonerData.SummonerLevel.Level.ToString() + " " + summonerData.SummonerLevelAndPoints.ExpPoints.ToString() + "/" + summonerData.SummonerLevel.ExpToNextLevel.ToString());

                        //Remove GAMEEND file
                        try
                        {
                            System.IO.File.Delete("Logs/" + lastSummonerData.Summoner.SumId.ToString() + ".GAMEEND");
                        }
                        catch (Exception)
                        {
                        }

                        if (summonerData.SummonerLevel.Level == 3)
                        {
                            Console.WriteLine("Buying EXP Boost!");
                            BuyExpBoost(await RiotCalls.GetStoreUrl());
                        }

                        if ((botLevelLimit == "LEVEL_5" && summonerData.SummonerLevel.Level >= 5) || (botLevelLimit == "LEVEL_10" && summonerData.SummonerLevel.Level >= 10) || (botLevelLimit == "LEVEL_30" && summonerData.SummonerLevel.Level >= 30))
                        {
                            System.IO.File.WriteAllText(@"Logs/" + userName + ".finished", "1");
                        }

                        dynamic infoFile = Config.Load("Logs/AccountInfo/" + userName + ".info");

                        infoFile.Info.Level      = summonerData.SummonerLevel.Level;
                        infoFile.Info.ExpBalance = summonerData.SummonerLevelAndPoints.ExpPoints.ToString() + "/" + summonerData.SummonerLevel.ExpToNextLevel.ToString();

                        infoFile.Save();
                        infoFile = null;

                        //Wait 5 Seconds for observerThreads!
                        //Thread.Sleep(5000);

                        //Make sure observerThread gets terminated
                        //try
                        //{
                        //    observerThread.Abort();
                        //}
                        //catch (Exception)
                        //{ }

                        doRoomStuff(); //Start Loop again
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("FAK:" + e.Message);
                restart();
            }
        }