Skip to content

Commit 40c6bce

Browse files
committed
Include friend names in SteamOnline
1 parent 96a33ad commit 40c6bce

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

ChobbyLauncher/ChobbyLoopbackMessages.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ public class DownloadFileProgress
121121
[ChobbyMessage]
122122
public class SteamOnline
123123
{
124+
124125
public string AuthToken { get; set; }
125-
public List<string> Friends { get; set; }
126+
public List<SteamFriend> Friends { get; set; }
126127
public string FriendSteamID { get; set; }
127128
public string SuggestedName { get; set; }
128129
public List<ulong> Dlc { get; set; }

ChobbyLauncher/ChobbylaLocalListener.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using PlasmaDownloader;
1616
using PlasmaShared;
1717
using ZkData;
18+
using static ChobbyLauncher.SteamOnline;
1819
using Timer = System.Threading.Timer;
1920

2021
namespace ChobbyLauncher
@@ -756,13 +757,13 @@ private async Task SendSteamOnline()
756757
{
757758
var friendId = initialConnectLobbyID != 0 ? steam.GetLobbyOwner(initialConnectLobbyID) : null;
758759

759-
760+
760761

761762
await
762763
SendCommand(new SteamOnline()
763764
{
764765
AuthToken = steam.AuthToken,
765-
Friends = steam.Friends.Select(x => x.ToString()).ToList(),
766+
Friends = steam.Friends,
766767
FriendSteamID = friendId?.ToString(),
767768
SuggestedName = steam.MySteamNameSanitized,
768769
Dlc = steam.GetDlcList()

ChobbyLauncher/SteamClient.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public enum OverlayOption
4747

4848
public string AuthToken { get; private set; }
4949

50-
public List<ulong> Friends { get; private set; }
50+
public List<SteamFriend> Friends { get; private set; }
5151
public bool IsOnline { get; private set; }
5252
public ChobbylaLocalListener Listener { get; set; }
5353

@@ -85,7 +85,7 @@ public void ConnectToSteam()
8585
public ulong? GetLobbyOwner(ulong lobbyID)
8686
{
8787
if (IsOnline)
88-
foreach (var f in GetFriends())
88+
foreach (var f in GetFriendIDs())
8989
{
9090
FriendGameInfo_t gi;
9191
SteamFriends.GetFriendGamePlayed(new CSteamID(f), out gi);
@@ -155,7 +155,7 @@ public void PrepareToHostP2PGame(SteamHostGameRequest request)
155155
ulong.TryParse(player.SteamID, out playerSteamID);
156156

157157
p2pProxies[playerSteamID] = null;
158-
SendSteamMessage(playerSteamID, new SteamP2PRequestPrepareProxy() {Channel = steamChannelCounter++});
158+
SendSteamMessage(playerSteamID, new SteamP2PRequestPrepareProxy() { Channel = steamChannelCounter++ });
159159
}
160160

161161
// wait for response
@@ -191,7 +191,7 @@ public void PrepareToHostP2PGame(SteamHostGameRequest request)
191191
ScriptPassword = player.ScriptPassword
192192
});
193193
}
194-
194+
195195
// send command to start spring to self
196196
Listener.SendCommand(new SteamHostGameSuccess() { HostPort = gameHostUdpPort });
197197
});
@@ -241,7 +241,20 @@ private string GetClientAuthTokenHex()
241241
}
242242

243243

244-
private List<ulong> GetFriends()
244+
private List<SteamFriend> getFriends()
245+
{
246+
if (IsOnline)
247+
{
248+
return GetFriendIDs().Select(x => new SteamFriend()
249+
{
250+
Name = SteamFriends.GetFriendPersonaName(x),
251+
SteamID = x.ToString()
252+
}).ToList();
253+
}
254+
return null;
255+
}
256+
257+
private List<ulong> GetFriendIDs()
245258
{
246259
if (IsOnline)
247260
{
@@ -274,7 +287,7 @@ private void OnSteamOnline()
274287
newConnectionCallback = Callback<P2PSessionRequest_t>.Create(t => SteamNetworking.AcceptP2PSessionWithUser(t.m_steamIDRemote));
275288
MySteamNameSanitized = Utils.StripInvalidLobbyNameChars(GetMyName());
276289

277-
290+
278291
var ev = new EventWaitHandle(false, EventResetMode.ManualReset);
279292
AuthToken = GetClientAuthTokenHex();
280293
CreateLobbyAsync((lobbyID) =>
@@ -283,7 +296,7 @@ private void OnSteamOnline()
283296
ev.Set();
284297
});
285298
SteamNetworking.AllowP2PPacketRelay(true);
286-
Friends = GetFriends();
299+
Friends = GetFriendIDs();
287300
ev.WaitOne(2000);
288301
SteamOnline?.Invoke();
289302
}
@@ -323,7 +336,7 @@ private void DisposeExistingProxies()
323336
/// </summary>
324337
private void ProcessMessage(ulong remoteUser, SteamP2PConfirmCreateProxy cmd)
325338
{
326-
p2pProxies[remoteUser] = new SteamP2PPortProxy(cmd.Channel, new CSteamID(remoteUser), gameHostUdpPort);
339+
p2pProxies[remoteUser] = new SteamP2PPortProxy(cmd.Channel, new CSteamID(remoteUser), gameHostUdpPort);
327340
}
328341

329342
/// <summary>
@@ -425,4 +438,11 @@ private void TimerOnElapsed(object sender)
425438
}
426439
}
427440
}
441+
442+
class SteamFriend
443+
{
444+
445+
public string SteamID;
446+
public string Name;
447+
}
428448
}

0 commit comments

Comments
 (0)