Exemplo n.º 1
0
        public override void OnEnter()
        {
            ulong    ID = ulong.Parse(this.steamID.Value);
            CSteamID steamID;

            steamID.m_SteamID = ID;

            switch (SteamFriends.GetFriendPersonaState(steamID))
            {
            case EPersonaState.k_EPersonaStateOffline:
                Fsm.Event(offline);
                if (personalState != null)
                {
                    personalState.Value = "Offline";
                }
                if (stateIndex != null)
                {
                    stateIndex.Value = 0;
                }
                break;

            case EPersonaState.k_EPersonaStateOnline:
                Fsm.Event(online);
                if (personalState != null)
                {
                    personalState.Value = "Online";
                }
                if (stateIndex != null)
                {
                    stateIndex.Value = 1;
                }
                break;

            case EPersonaState.k_EPersonaStateBusy:
                Fsm.Event(busy);
                if (personalState != null)
                {
                    personalState.Value = "Busy";
                }
                if (stateIndex != null)
                {
                    stateIndex.Value = 2;
                }
                break;

            case EPersonaState.k_EPersonaStateAway:
                Fsm.Event(away);
                if (personalState != null)
                {
                    personalState.Value = "Away";
                }
                if (stateIndex != null)
                {
                    stateIndex.Value = 3;
                }
                break;

            case EPersonaState.k_EPersonaStateSnooze:
                Fsm.Event(snooze);
                if (personalState != null)
                {
                    personalState.Value = "Snooze";
                }
                if (stateIndex != null)
                {
                    stateIndex.Value = 4;
                }
                break;

            case EPersonaState.k_EPersonaStateLookingToTrade:
                Fsm.Event(LookingToTrade);
                if (personalState != null)
                {
                    personalState.Value = "Looking to trade";
                }
                if (stateIndex != null)
                {
                    stateIndex.Value = 5;
                }
                break;

            case EPersonaState.k_EPersonaStateLookingToPlay:
                Fsm.Event(lookingToPlay);
                if (personalState != null)
                {
                    personalState.Value = "Looking to play";
                }
                if (stateIndex != null)
                {
                    stateIndex.Value = 6;
                }
                break;

            case EPersonaState.k_EPersonaStateMax:
                Fsm.Event(max);
                if (personalState != null)
                {
                    personalState.Value = "Max";
                }
                if (stateIndex != null)
                {
                    stateIndex.Value = 7;
                }
                break;
            }
            Finish();
        }
Exemplo n.º 2
0
        public static void InitCallbacks()
        {
            RimWorldAppId = SteamUtils.GetAppID();

            sessionReq = Callback <P2PSessionRequest_t> .Create(req =>
            {
                var session = Multiplayer.session;
                if (session?.localSettings != null && session.localSettings.steam && !session.pendingSteam.Contains(req.m_steamIDRemote))
                {
                    if (MultiplayerMod.settings.autoAcceptSteam)
                    {
                        SteamNetworking.AcceptP2PSessionWithUser(req.m_steamIDRemote);
                    }
                    else
                    {
                        session.pendingSteam.Add(req.m_steamIDRemote);
                    }

                    session.knownUsers.Add(req.m_steamIDRemote);
                    session.NotifyChat();

                    SteamFriends.RequestUserInformation(req.m_steamIDRemote, true);
                }
            });

            friendRchpUpdate = Callback <FriendRichPresenceUpdate_t> .Create(update =>
            {
            });

            gameJoinReq = Callback <GameRichPresenceJoinRequested_t> .Create(req =>
            {
            });

            personaChange = Callback <PersonaStateChange_t> .Create(change =>
            {
            });

            p2pFail = Callback <P2PSessionConnectFail_t> .Create(fail =>
            {
                var session = Multiplayer.session;
                if (session == null)
                {
                    return;
                }

                var remoteId = fail.m_steamIDRemote;
                var error    = (EP2PSessionError)fail.m_eP2PSessionError;

                if (Multiplayer.Client is SteamBaseConn clientConn && clientConn.remoteId == remoteId)
                {
                    clientConn.OnError(error);
                }

                var server = Multiplayer.LocalServer;
                if (server == null)
                {
                    return;
                }

                server.Enqueue(() =>
                {
                    var conn = server.players.Select(p => p.conn).OfType <SteamBaseConn>().FirstOrDefault(c => c.remoteId == remoteId);
                    if (conn != null)
                    {
                        conn.OnError(error);
                    }
                });
            });
        }
Exemplo n.º 3
0
    void DrawModWindow()
    {
        const float hSpacing = 250.0f;

        ImGui.SetNextWindowSize(new Vector2(700.0f, 300.0f), ImGuiCond.FirstUseEver);

        ImGui.PushStyleColor(ImGuiCol.WindowBg, backgroundColor);
        ImGui.PushStyleColor(ImGuiCol.Button, buttonColor);
        ImGui.PushStyleColor(ImGuiCol.ButtonHovered, buttonHoveredColor);
        ImGui.PushStyleColor(ImGuiCol.ButtonActive, buttonActiveColor);
        ImGui.PushStyleColor(ImGuiCol.TitleBgActive, headerColor);
        ImGui.PushStyleColor(ImGuiCol.PopupBg, buttonColor);
        ImGui.PushStyleColor(ImGuiCol.ResizeGrip, buttonColor);
        ImGui.PushStyleColor(ImGuiCol.ResizeGripHovered, buttonActiveColor);
        ImGui.PushStyleColor(ImGuiCol.ResizeGripActive, buttonActiveColor);
        ImGui.PushStyleColor(ImGuiCol.FrameBg, buttonColor);
        ImGui.PushStyleColor(ImGuiCol.FrameBgHovered, buttonHoveredColor);
        ImGui.PushStyleColor(ImGuiCol.FrameBgActive, buttonActiveColor);
        ImGui.PushStyleColor(ImGuiCol.CheckMark, headerColor);

        ImGui.Begin("Mod window");
        ImGui.Text("Installed mods"); // TODO gray them out when mods are not enabled

        ImGui.SameLine();
        ImGui.PushStyleColor(ImGuiCol.Text, buttonTextColor);
        if (ImGui.Button("Refresh Steam"))
        {
            QueryPersonalWorkshopItems();
            loadItems = true;
        }
        ImGui.PopStyleColor(1);

        for (int i = 0; i < ModManager.importedMods.Count; i++)
        {
            Mod mod = ModManager.importedMods[i];

            ImGui.Text(mod.steamworksItem.GetName());
            ImGui.SameLine(hSpacing);
            ImGui.Text(mod.GetTypeString());
            ImGui.SameLine(1.2f * hSpacing);
            ImGui.PushStyleColor(ImGuiCol.Text, buttonTextColor);
            if (ImGui.Button("Show info##" + i))
            {
                if (uploadingItem != null)
                {
                    uploadingItem.waiting_for_create = false;
                }
                uploadingItem = mod.steamworksItem;
                uploadingItem.waiting_for_create = true;
            }
            if (ImGui.IsItemHovered())
            {
                ImGui.SetTooltip("Show mod info and Workshop upload window");
            }
            ImGui.PopStyleColor(1);

            ImGui.SameLine();
            ImGui.Checkbox($"Disabled ##{mod.path}", ref mod.steamworksItem.ignore);

            ImGui.PushStyleColor(ImGuiCol.Text, buttonTextColor);
            if (!mod.IsLocalMod())
            {
                ImGui.SameLine();
                if (ImGui.Button("Unsubscribe##" + i))
                {
                    ModManager.importedMods.Remove(mod);

                    SteamUGC.UnsubscribeItem(mod.steamworksItem.GetSteamworksId());
                    QueryPersonalWorkshopItems();
                    i--;
                    continue;
                }
                ImGui.SameLine();
                if (ImGui.Button("Show in Steam##" + i))
                {
                    string itemPath = $"steam://url/CommunityFilePage/{mod.steamworksItem.GetSteamworksId()}";
                    SteamFriends.ActivateGameOverlayToWebPage(itemPath);
                }
                if (ImGui.IsItemHovered())
                {
                    ImGui.SetTooltip("Open Steam overlay to Workshop page");
                }
            }
            ImGui.PopStyleColor(1);
        }

        ImGui.PushStyleColor(ImGuiCol.Text, buttonTextColor);
        if (ImGui.Button("Close"))
        {
            optionsmenuscript.show_mod_ui = false;
        }
        ImGui.PopStyleColor(1);

        ImGui.End();

        ImGui.PopStyleColor(13);
    }
Exemplo n.º 4
0
 private void OnDisconnect()
 {
     SteamFriends.ClearRichPresence();
     this._hasLocalHost    = false;
     Netplay.OnDisconnect -= new Action(this.OnDisconnect);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Opens the store page to the DLC
 /// </summary>
 /// <param name="flag"></param>
 public void OpenStore(EOverlayToStoreFlag flag = EOverlayToStoreFlag.k_EOverlayToStoreFlag_None)
 {
     SteamFriends.ActivateGameOverlayToStore(AppId, flag);
 }
Exemplo n.º 6
0
 public static string GetUsername(ulong steamID)
 {
     // todo
     return(SteamFriends.GetPlayerNickname(new CSteamID(steamID)));
 }
Exemplo n.º 7
0
        /// <summary>
        ///     Handles the username selection process
        /// </summary>
        /// <param name="text"></param>
        private void OnBoxSubmitted(string text)
        {
            DialogManager.Dismiss();

            ThreadScheduler.Run(() =>
            {
                OnlineManager.Client.ChooseUsername(text, SteamUser.GetSteamID().m_SteamID, SteamFriends.GetPersonaName(),
                                                    SteamManager.PTicket, SteamManager.PcbTicket);
            });
        }
Exemplo n.º 8
0
 public static void ShowPlayers(PlayerIndex player)
 {
     SteamFriends.ActivateGameOverlay("Players");
 }
Exemplo n.º 9
0
 public static void ShowAchievementsEXT(PlayerIndex player)
 {
     SteamFriends.ActivateGameOverlay("Achievements");
 }
Exemplo n.º 10
0
 public static void ShowMessages(PlayerIndex player)
 {
     // If a message is pending then it'll just be there? -flibit
     SteamFriends.ActivateGameOverlay(null);
 }
Exemplo n.º 11
0
 public static void ShowPlayerReview(PlayerIndex player, Gamer gamer)
 {
     // Comments/Rating are on the user profile
     SteamFriends.ActivateGameOverlayToUser("steamid", gamer.steamID);
 }
Exemplo n.º 12
0
 public static void ShowGamerCard(PlayerIndex player, Gamer gamer)
 {
     SteamFriends.ActivateGameOverlayToUser("steamid", gamer.steamID);
 }
Exemplo n.º 13
0
    /// <summary>
    /// the refresh function that changes things every second based on updated data.
    /// </summary>
    void refresh()
    {
        ToggleStatus.text = "Private Lobby Toggle: " + friendslist;
        if (steammangercheck.issteamversion == false)
        {
            Users.GetLoggedInUser().OnComplete(GetLoggedInUserCallback);
            Users.GetLoggedInUserFriends().OnComplete((Message <UserList> msg) =>
            {
                if (msg.IsError == false)
                {
                    foreach (var friend in msg.Data)
                    {
                        Debug.Log("friend: " + friend);
                        friendslisttemp.Add(friend.OculusID);
                    }
                }
                else
                {
                    Debug.Log(msg.GetError().Message);
                }
            });
        }
        else
        {
            PhotonNetwork.playerName = PhotonNetwork.playerName = SteamFriends.GetPersonaName();
        }

        if (PhotonNetwork.connectedAndReady == true)
        {
            if (friendslist == false)
            {
                int roomliststart = ((roomlistcount) * 5);
                if (PhotonNetwork.GetRoomList().Length == 0)
                {
                    Debug.Log("..no games available..");
                    for (int p = 0; p < 5; p++)
                    {
                        matchtext[p].text = "Slot empty";
                    }
                }
                else
                {
                    Debug.Log(PhotonNetwork.GetRoomList().Length + " games available..");
                    List <RoomInfo> gameslist = new List <RoomInfo>();
                    foreach (RoomInfo game in PhotonNetwork.GetRoomList())
                    {
                        Debug.Log((string)game.CustomProperties["Fr"]);
                        if ((string)game.CustomProperties["Fr"] == "false")
                        {
                            gameslist.Add(game);
                        }
                    }
                    roomscurrent = gameslist;
                    //Room listing: simply call GetRoomList: no need to fetch/poll whatever!
                    int i = 0;
                    int b = 0;
                    for (int a = 0; a < 5; a++)
                    {
                        matchtext[a].text = "Slot empty";
                    }
                    foreach (RoomInfo game in gameslist)
                    {
                        if (i < 5 && b > (roomliststart - 1) && b < roomliststart + 5)
                        {
                            matchtext[i].text = game.Name + " " + game.PlayerCount + "/" + game.MaxPlayers + " state: " + (string)game.CustomProperties["st"] + " 3v3: " + (string)game.CustomProperties["3v3"];
                            i++;
                        }
                        b++;
                    }
                }
            }
            else
            {
                int roomliststart = ((roomlistcount) * 5);
                if (PhotonNetwork.GetRoomList().Length == 0)
                {
                    Debug.Log("..no games available..");
                    for (int p = 0; p < 5; p++)
                    {
                        matchtext[p].text = "Slot empty";
                    }
                }
                else
                {
                    List <RoomInfo> gameslist = new List <RoomInfo>();
                    foreach (RoomInfo game in PhotonNetwork.GetRoomList())
                    {
                        Debug.Log((string)game.CustomProperties["Un"]);
                        if ((string)game.CustomProperties["isFriendsOnly"] == "true" && friendslisttemp.Contains((string)game.CustomProperties["Un"]))
                        {
                            gameslist.Add(game);
                        }
                    }
                    roomscurrent = gameslist;
                    int i = 0;
                    int b = 0;
                    for (int a = 0; a < 5; a++)
                    {
                        matchtext[a].text = "Slot empty";
                    }
                    foreach (RoomInfo game in gameslist)
                    {
                        if (i < 5 && b > (roomliststart - 1) && b < roomliststart + 5)
                        {
                            matchtext[i].text = game.Name + " " + game.PlayerCount + "/" + game.MaxPlayers + " state: " + (string)game.CustomProperties["st"] + " 3v3: " + (string)game.CustomProperties["3v3"];
                            i++;
                        }
                        b++;
                    }
                }
            }

            pingtext.text          = "ping: " + PhotonNetwork.networkingPeer.RoundTripTime.ToString() + "ms";
            PlayersOnlinetext.text = "Current Players: " + PhotonNetwork.countOfPlayers.ToString();
            float page = Mathf.Ceil(PhotonNetwork.GetRoomList().Length / 6);
            if (page == 0)
            {
                page = 1;
            }
            int temproomlist = roomlistcount + 1;
            pagenumtext.text = "page: " + temproomlist + " out of " + page.ToString();
        }
    }
Exemplo n.º 14
0
        public static Texture GetAvatarTexture(ulong steamid)
        {
            SteamFriends.RequestUserInformation(new CSteamID(steamid), false);

            return(SteamAvatarCache.FindTexture(steamid));
        }
Exemplo n.º 15
0
 public override string GetUsername()
 {
     return(SteamFriends.GetPersonaName());
 }
 private void OnDisconnect()
 {
     SteamFriends.ClearRichPresence();
     _hasLocalHost         = false;
     Netplay.OnDisconnect -= OnDisconnect;
 }
Exemplo n.º 17
0
 public override void OpenJoinInterface()
 {
     SteamFriends.ActivateGameOverlay("Friends");
 }
Exemplo n.º 18
0
    // Use this for initialization
    void Start()
    {
        DontDestroyOnLoad(lobbyCanvas);

        // fill out all callbacks on SteamHub.Lobby_Callbacks
        var callbacks = new SteamHub.Lobby_Callbacks
        {
            LobbyCreated     = MyCallbacks_LobbyCreated,
            LobbyEntered     = MyCallbacks_LobbyEntered,
            LobbyListUpdated = MyCallbacks_LobbyListUpdated,
            LobbyDataUpdated = MyCallbacks_LobbyDataUpdated,
            LobbyChatUpdate  = MyCallbacks_LobbyChatUpdate,
            LobbyChatMessage = MyCallbacks_LobbyChatMessage
        };

        // call LobbyManager_Start
        SteamHub.LobbyManager_Start(callbacks);

        Text t = createLobbyText.GetComponent <Text>();

        t.text = "Create or join a lobby please";

        SteamHub.Lobby_RefreshList();

        if (SteamManager.Initialized && profilePic != null)
        {
            profileName.text = SteamFriends.GetPersonaName();
            SteamFriends.SetRichPresence("status", "Main Menu");

            //display profile pic in top right
            CSteamID m_Friend = SteamUser.GetSteamID();

            int FriendAvatar = SteamFriends.GetLargeFriendAvatar(m_Friend);
            print("SteamFriends.GetLargeFriendAvatar(" + m_Friend + ") - " + FriendAvatar);

            uint ImageWidth;
            uint ImageHeight;
            bool ret = Steamworks.SteamUtils.GetImageSize(FriendAvatar, out ImageWidth, out ImageHeight);

            if (ret && ImageWidth > 0 && ImageHeight > 0)
            {
                byte[] Image = new byte[ImageWidth * ImageHeight * 4];

                ret = Steamworks.SteamUtils.GetImageRGBA(FriendAvatar, Image, (int)(ImageWidth * ImageHeight * 4));
                if (ret)
                {
                    m_LargeAvatar = new Texture2D((int)ImageWidth, (int)ImageHeight, TextureFormat.RGBA32, false, true);
                    m_LargeAvatar.LoadRawTextureData(Image);
                    m_LargeAvatar.Apply();

                    profilePic.GetComponent <Image>().sprite = Sprite.Create(m_LargeAvatar, new Rect(0, 0, 184, 184), new Vector2(184, 184));
                }
            }
        }

        if (SteamManager.Initialized)
        {
            Debug.Log("Steam Online");

            steamNotification.GetComponent <Text>().color = Color.green;
            steamNotification.GetComponent <Text>().text  = "STEAM ONLINE";
            // steamNotification.SetActive(false);

            //bool ret0 =
            SteamUserStats.RequestCurrentStats();

            //we're going to use Spacewar's "NumWins" to track kills and "AverageSpeed" as ELO for matchmaking
            //NumLosses as deaths?
            //float myELO;
            //SteamUserStats.GetStat("AverageSpeed", out myELO);
            //bool ret4 = SteamUserStats.ResetAllStats(true);
            int Data;
            //bool ret =
            SteamUserStats.GetStat("NumGames", out Data);
            // Debug.Log(Data + " " + ret);

            currentEloText.GetComponent <Text>().text = "CURRENT ELO: " + Data;

            currentEloVisualFeedback.fillAmount = Data / 100.0f;

            // int m_nTotalNumWins;
            //SteamUserStats.GetStat("NumWins", out m_nTotalNumWins);
            //Debug.Log(m_nTotalNumWins);

            //SteamUserStats.SetStat("NumWins", 10);

            //bool bSuccess = SteamUserStats.StoreStats();
            //Debug.Log(bSuccess);
        }
        else
        {
            Debug.Log("Steam Offline");

            steamNotification.GetComponent <Text>().color = Color.red;
            steamNotification.GetComponent <Text>().text  = "STEAM OFFLINE";
        }
    }
Exemplo n.º 19
0
        public MySteamService(bool isDedicated, uint appId)
            : base(true, appId)
        {
            // TODO: Add protection for this mess... somewhere
            GameServer.Shutdown();
            var steam = typeof(MySteamServiceBase);

            steam.GetField("m_gameServer", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(this, null);

            steam.GetProperty("AppId").GetSetMethod(true).Invoke(this, new object[] { appId });
            if (isDedicated)
            {
                steam.GetProperty("SteamServerAPI").GetSetMethod(true).Invoke(this, new object[] { null });
                steam.GetField("m_gameServer").SetValue(this, new VRage.Steam.MySteamGameServer());

                var method = typeof(MySteamServiceBase).GetMethod("OnModServerDownloaded", System.Reflection.BindingFlags.NonPublic);
                var del    = method.CreateDelegate <Callback <DownloadItemResult_t> .DispatchDelegate>(this);
                steam.GetField("m_modServerDownload").SetValue(this, Callback <DownloadItemResult_t> .CreateGameServer(new Callback <DownloadItemResult_t> .DispatchDelegate(del)));
            }
            else
            {
                steam.GetProperty("IsActive").GetSetMethod(true).Invoke(this, new object[] { SteamAPI.Init() });

                if (IsActive)
                {
                    steam.GetField("SteamUserId", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(this, SteamUser.GetSteamID());
                    steam.GetProperty("UserId").GetSetMethod(true).Invoke(this, new object[] { (ulong)SteamUser.GetSteamID() });
                    steam.GetProperty("UserName").GetSetMethod(true).Invoke(this, new object[] { SteamFriends.GetPersonaName() });
                    steam.GetProperty("OwnsGame").GetSetMethod(true).Invoke(this, new object[] {
                        SteamUser.UserHasLicenseForApp(SteamUser.GetSteamID(), (AppId_t)appId) == EUserHasLicenseForAppResult.k_EUserHasLicenseResultHasLicense
                    });
                    steam.GetProperty("UserUniverse").GetSetMethod(true).Invoke(this, new object[] { (MyGameServiceUniverse)SteamUtils.GetConnectedUniverse() });

                    string pchName;
                    steam.GetProperty("BranchName").GetSetMethod(true).Invoke(this, new object[] { SteamApps.GetCurrentBetaName(out pchName, 512) ? pchName : "default" });

                    SteamUserStats.RequestCurrentStats();

                    steam.GetProperty("InventoryAPI").GetSetMethod(true).Invoke(this, new object[] { new VRage.Steam.MySteamInventory() });

                    steam.GetMethod("RegisterCallbacks",
                                    System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
                    .Invoke(this, null);

#if SE
                    steam.GetField("m_remoteStorage", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(this, new VRage.Steam.MySteamRemoteStorage());
#endif
                }
            }

            steam.GetProperty("Peer2Peer").GetSetMethod(true).Invoke(this, new object[] { new VRage.Steam.MySteamPeer2Peer() });
        }
Exemplo n.º 20
0
    void MyCallbacks_LobbyListUpdated()
    {
        // Clear the Lobby List and Members List Panels
        foreach (Transform child in LobbyDetailsPanel.transform)
        {
            Destroy(child.gameObject);
        }

        foreach (Transform child in LobbyMembersListPanel.transform)
        {
            Destroy(child.gameObject);
        }

        // Instantiate the gameobject for the Each Lobby panel row
        foreach (var lobby in SteamHub.LobbyList)
        {
            string lobbyName = lobby.GetData <String>("name");
            if (lobbyName == null || lobbyName == "")
            {
                lobbyName = "<unnamed>";
            }

            GameObject lobbyRow = (GameObject)Instantiate(LobbyDetailsRowPanelPrefab, new Vector3(1, 1, 1), Quaternion.identity);
            lobbyRow.transform.SetParent(LobbyDetailsPanel.transform, false);
            lobbyRow.transform.localScale = new Vector3(1, 1, 1);
            lobbyRow.name = "Lobby details row for Lobby ID #" + lobby.LobbyId.ToString();

            Text t2 = lobbyRow.transform.Find("Lobby Details Text").GetComponent <Text>();

            Boolean isLobbyActive = (SteamHub.LobbyActive != null && lobby.LobbyId == SteamHub.LobbyActive.LobbyId);

            int lobbyMaxMembers = SteamMatchmaking.GetLobbyMemberLimit(lobby.LobbyId);

            String str = isLobbyActive ? "(A) " : "     ";
            str += "Lobby \"" + lobbyName + "\" #";
            str += lobby.LobbyId.ToString() + ": ";
            // str += "[" + lobby.MembersCount.ToString() + "/" + lobbyMaxMembers.ToString() + "] ";
            str += lobby.IsOwner ? " (OWNER)" : "";

            t2.text = str;

            Text t1 = lobbyRow.transform.Find("NumberOfPlayerText").GetComponent <Text>();
            t1.text = lobby.MembersCount.ToString() + "/" + lobbyMaxMembers.ToString();

            Image fill = lobbyRow.transform.Find("VisualFeedback").GetComponent <Image>();
            fill.fillAmount = (float)lobby.MembersCount / lobbyMaxMembers;

            Button joinButton = lobbyRow.transform.Find("Join Button").GetComponent <Button>();
            if (isLobbyActive)
            {
                // Provide a leave button
                Text joinButtonLabelText = (Text)joinButton.transform.GetChild(0).GetComponent <Text>();
                joinButtonLabelText.text = "LEAVE";
                var lob = lobby; // Capture it for the lambda
                joinButton.onClick.AddListener(() => ui_click_leaveLobbyButtonPressed(joinButton, lob));

                // Instantiate the gameobject for the Each Lobby panel row
                foreach (var m in lobby.AllMembers)
                {
                    GameObject memberRow = (GameObject)Instantiate(LobbyMemberDetailsRowPanelPrefab, new Vector3(1, 1, 1), Quaternion.identity);
                    memberRow.transform.SetParent(LobbyMembersListPanel.transform, false);
                    memberRow.transform.localScale = new Vector3(1, 1, 1);
                    memberRow.name = "Member details row for Member ID #" + m.m_SteamID.ToString();
                    Text t3 = memberRow.transform.Find("Member Details Text").GetComponent <Text>();

                    Image LargeAvatar = memberRow.transform.Find("ProfileImage").GetComponent <Image>();

                    int  FriendAvatar = SteamFriends.GetSmallFriendAvatar(m);
                    uint ImageWidth;
                    uint ImageHeight;
                    bool ret = Steamworks.SteamUtils.GetImageSize(FriendAvatar, out ImageWidth, out ImageHeight);

                    if (ret && ImageWidth > 0 && ImageHeight > 0)
                    {
                        byte[] Image = new byte[ImageWidth * ImageHeight * 4];

                        ret = Steamworks.SteamUtils.GetImageRGBA(FriendAvatar, Image, (int)(ImageWidth * ImageHeight * 4));
                        if (ret)
                        {
                            m_LargeAvatar = new Texture2D((int)ImageWidth, (int)ImageHeight, TextureFormat.RGBA32, false, true);
                            m_LargeAvatar.LoadRawTextureData(Image);
                            m_LargeAvatar.Apply();

                            LargeAvatar.GetComponent <Image>().sprite = Sprite.Create(m_LargeAvatar, new Rect(0, 0, 32, 32), new Vector2(32, 32));
                        }
                    }


                    string mName  = SteamFriends.GetFriendPersonaName(m);
                    string inGame = "";
                    if (lobby.GetData <string>(m.ToString()) == "true")
                    {
                        inGame = " (IN GAME) ";
                    }
                    t3.text = inGame + "Member \"" + mName + "\" ID #" + m.m_SteamID.ToString();

                    Button kickButton = memberRow.transform.Find("Kick Button").GetComponent <Button>();
                    if (lobby.IsOwner)
                    {
                        var lobKick      = lobby; // Capture it for the lambda that follows
                        var memberToKick = m;
                        kickButton.onClick.AddListener(() => ui_click_kickFromLobbyButtonPressed(kickButton, lobKick, memberToKick));
                    }
                    else
                    {
                        kickButton.interactable = false;
                    }

                    if (lobby.OwnerId == (CSteamID)m.m_SteamID)
                    {
                        kickButton.interactable = false;
                    }
                }
            }
            else
            {
                // Provide a join button
                var lobJoin = lobby; // Capture it for the lambda that follows
                joinButton.onClick.AddListener(() => ui_click_joinLobbyButtonPressed(joinButton, lobJoin));
            }
        }

        // Yay all done
    }
Exemplo n.º 21
0
 public override void Close(RemoteAddress address)
 {
     SteamFriends.ClearRichPresence();
     this.Close(this.RemoteAddressToSteamId(address));
 }
Exemplo n.º 22
0
        public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false, bool process = false)
        {
            userHandlers = new Dictionary <SteamID, UserHandler>();
            logOnDetails = new SteamUser.LogOnDetails
            {
                Username = config.Username,
                Password = config.Password
            };
            DisplayName       = config.DisplayName;
            ChatResponse      = config.ChatResponse;
            DisplayNamePrefix = config.DisplayNamePrefix;
            Admins            = config.Admins;
            ApiKey            = !String.IsNullOrEmpty(config.ApiKey) ? config.ApiKey : apiKey;
            isProccess        = process;
            try
            {
                if (config.LogLevel != null)
                {
                    consoleLogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true);
                    Console.WriteLine(@"(Console) LogLevel configuration parameter used in bot {0} is depreciated and may be removed in future versions. Please use ConsoleLogLevel instead.", DisplayName);
                }
                else
                {
                    consoleLogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.ConsoleLogLevel, true);
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine(@"(Console) ConsoleLogLevel invalid or unspecified for bot {0}. Defaulting to ""Info""", DisplayName);
                consoleLogLevel = Log.LogLevel.Info;
            }

            try
            {
                fileLogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.FileLogLevel, true);
            }
            catch (ArgumentException)
            {
                Console.WriteLine(@"(Console) FileLogLevel invalid or unspecified for bot {0}. Defaulting to ""Info""", DisplayName);
                fileLogLevel = Log.LogLevel.Info;
            }

            logFile = config.LogFile;
            CreateLog();
            createHandler   = handlerCreator;
            BotControlClass = config.BotControlClass;
            SteamWeb        = new SteamWeb();

            // Hacking around https
            ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;

            Log.Debug("Initializing Steam Bot...");
            SteamClient = new SteamClient();
            SteamClient.AddHandler(new SteamNotifications());
            SteamTrade           = SteamClient.GetHandler <SteamTrading>();
            SteamUser            = SteamClient.GetHandler <SteamUser>();
            SteamFriends         = SteamClient.GetHandler <SteamFriends>();
            SteamGameCoordinator = SteamClient.GetHandler <SteamGameCoordinator>();

            botThread = new BackgroundWorker {
                WorkerSupportsCancellation = true
            };
            botThread.DoWork             += BackgroundWorkerOnDoWork;
            botThread.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted;
            botThread.RunWorkerAsync();
        }
Exemplo n.º 23
0
        public override void Update()
        {
            base.Update();

            foreach (ulong s in MonklandSteamManager.connectedPlayers)
            {
                if (playerHash.Contains(s))
                {
                    continue;
                }

                MenuLabel newLabel = new MenuLabel(this.menu, this, SteamFriends.GetFriendPersonaName((CSteamID)s), new Vector2(5, 0), new Vector2(this.size.x - 10, 20), false);
                playerHash.Add(s);
                playerLabels.Add(s, newLabel);
                this.subObjects.Add(newLabel);
            }

            //Update stuff
            {
                //The total height in pixels that the players take up on the scroll menu
                float messagePixelHeight = 5 + (playerLabels.Count * 25);
                //The max height the scrollbar can display
                float maxDisplayHeight     = this.size.y - 30;
                float maxDisplayTransition = this.size.y - 40;

                float difference = messagePixelHeight - maxDisplayHeight;

                if (difference < 0)
                {
                    scrollValue = 0;
                }

                int i = 0;

                foreach (KeyValuePair <ulong, MenuLabel> kvp in playerLabels)
                {
                    MenuLabel item    = kvp.Value;
                    float     actualY = 5.01f + ((playerLabels.Count - i - 1) * 25) - (difference * scrollValue);
                    item.pos = new Vector2(item.pos.x, actualY);

                    float targetAlpha = 1;

                    if (actualY < 10)
                    {
                        targetAlpha = actualY / 10f;
                    }
                    else if (actualY > maxDisplayHeight)
                    {
                        targetAlpha = 0;
                    }
                    else if (actualY > maxDisplayTransition)
                    {
                        targetAlpha = 1 - ((actualY - maxDisplayTransition) / 10f);
                    }
                    else
                    {
                        targetAlpha = 1;
                    }

                    item.label.color = MonklandSteamManager.GameManager.readiedPlayers.Contains(kvp.Key) ? Color.green : Color.red;
                    item.label.alpha = targetAlpha;

                    i++;
                }
            }
        }
Exemplo n.º 24
0
        public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false)
        {
            logOnDetails = new SteamUser.LogOnDetails
            {
                Username = config.Username,
                Password = config.Password
            };
            DisplayName  = config.DisplayName;
            ChatResponse = config.ChatResponse;
            MaximumTradeTime = config.MaximumTradeTime;
            MaximiumActionGap = config.MaximumActionGap;
            DisplayNamePrefix = config.DisplayNamePrefix;
            TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval;
            hatBuyPrice= config.HatBuyPrice;
            hatSellPrice= config.HatSellPrice;
            maxRequestTime= config.MaxRequestTime;
            craftHatSellPrice = config.CraftHatSellPrice;
            Admins       = config.Admins;
            this.apiKey  = apiKey;
            try
            {
                LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'");
                LogLevel = Log.LogLevel.Info;
            }
            log          = new Log (config.LogFile, this.DisplayName, LogLevel);
            CreateHandler = handlerCreator;
            BotControlClass = config.BotControlClass;

            // Hacking around https
            ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;

            log.Debug ("Initializing Steam Bot...");
            SteamClient = new SteamClient();
            SteamTrade = SteamClient.GetHandler<SteamTrading>();
            SteamUser = SteamClient.GetHandler<SteamUser>();
            SteamFriends = SteamClient.GetHandler<SteamFriends>();
            log.Info ("Connecting...");
            SteamClient.Connect();
            
            Thread CallbackThread = new Thread(() => // Callback Handling
            {
                while (true)
                {
                    CallbackMsg msg = SteamClient.WaitForCallback (true);

                    HandleSteamMessage (msg);
                }
            });
            new Thread(() =>
                {
                    while (true)
                    {
                        Thread.Sleep(1000);
                        if (currentRequest.User != null)
                        {
                            DateTime RequestTimeout = RequestTime.AddSeconds(maxRequestTime);
                            int untilTradeTimeout = (int)Math.Round((RequestTimeout - DateTime.Now).TotalSeconds);
                            if (untilTradeTimeout <= 0 && (MySQL.getItem().User != null))
                            {
                                SteamFriends.SendChatMessage(currentRequest.User, EChatEntryType.ChatMsg, "Sorry, but your request took too long");
                                NewRequest(MySQL.RequestStatus.Timedout);
                                log.Warn("Request timedout");
                            }
                        }
                    }
                }).Start();
            CallbackThread.Start();
            log.Success ("Done Loading Bot!");
            CallbackThread.Join();
        }