mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Caches created LobbyType to be assigned as a LobbyData to be referenced by other members in the lobby.
Because there is no GetLobbyType, provides a layer in which all users can get a LobbyType from LobbyData.
This commit is contained in:
parent
e1c738fc8b
commit
c40037784e
@ -29,7 +29,7 @@ public enum Type : int
|
|||||||
FriendsOnly = SteamNative.LobbyType.FriendsOnly,
|
FriendsOnly = SteamNative.LobbyType.FriendsOnly,
|
||||||
Public = SteamNative.LobbyType.Public,
|
Public = SteamNative.LobbyType.Public,
|
||||||
Invisible = SteamNative.LobbyType.Invisible,
|
Invisible = SteamNative.LobbyType.Invisible,
|
||||||
None
|
Error //happens if you try to get this when you aren't in a valid lobby
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Client client;
|
internal Client client;
|
||||||
@ -37,7 +37,7 @@ public enum Type : int
|
|||||||
public Lobby(Client c)
|
public Lobby(Client c)
|
||||||
{
|
{
|
||||||
client = c;
|
client = c;
|
||||||
SteamNative.LobbyDataUpdate_t.RegisterCallback(client, OnLobbyDataUpdated);
|
SteamNative.LobbyDataUpdate_t.RegisterCallback(client, OnLobbyDataUpdatedAPI);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -84,9 +84,11 @@ void OnLobbyJoinedAPI(LobbyEnter_t callback, bool error)
|
|||||||
public void Create(Lobby.Type lobbyType, int maxMembers)
|
public void Create(Lobby.Type lobbyType, int maxMembers)
|
||||||
{
|
{
|
||||||
client.native.matchmaking.CreateLobby((SteamNative.LobbyType)lobbyType, maxMembers, OnLobbyCreatedAPI);
|
client.native.matchmaking.CreateLobby((SteamNative.LobbyType)lobbyType, maxMembers, OnLobbyCreatedAPI);
|
||||||
LobbyType = lobbyType;
|
createdLobbyType = lobbyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal Type createdLobbyType;
|
||||||
|
|
||||||
internal void OnLobbyCreatedAPI(LobbyCreated_t callback, bool error)
|
internal void OnLobbyCreatedAPI(LobbyCreated_t callback, bool error)
|
||||||
{
|
{
|
||||||
//from SpaceWarClient.cpp 793
|
//from SpaceWarClient.cpp 793
|
||||||
@ -102,7 +104,9 @@ internal void OnLobbyCreatedAPI(LobbyCreated_t callback, bool error)
|
|||||||
CurrentLobbyData = new LobbyData(client, CurrentLobby);
|
CurrentLobbyData = new LobbyData(client, CurrentLobby);
|
||||||
Name = client.Username + "'s Lobby";
|
Name = client.Username + "'s Lobby";
|
||||||
CurrentLobbyData.SetData("appid", client.AppId.ToString());
|
CurrentLobbyData.SetData("appid", client.AppId.ToString());
|
||||||
|
LobbyType = createdLobbyType;
|
||||||
CurrentLobbyData.SetData("lobbytype", LobbyType.ToString());
|
CurrentLobbyData.SetData("lobbytype", LobbyType.ToString());
|
||||||
|
Joinable = true;
|
||||||
if (OnLobbyCreated != null) { OnLobbyCreated(true); }
|
if (OnLobbyCreated != null) { OnLobbyCreated(true); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +119,7 @@ public class LobbyData
|
|||||||
{
|
{
|
||||||
internal Client client;
|
internal Client client;
|
||||||
internal ulong lobby;
|
internal ulong lobby;
|
||||||
internal Dictionary<string, string> data;
|
internal Dictionary<string, string> data;
|
||||||
|
|
||||||
public LobbyData(Client c, ulong l)
|
public LobbyData(Client c, ulong l)
|
||||||
{
|
{
|
||||||
@ -134,6 +138,16 @@ public string GetData(string k)
|
|||||||
return "ERROR: key not found";
|
return "ERROR: key not found";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<KeyValuePair<string,string>> GetAllData()
|
||||||
|
{
|
||||||
|
List<KeyValuePair<string, string>> returnData = new List<KeyValuePair<string, string>>();
|
||||||
|
foreach(KeyValuePair<string, string> item in data)
|
||||||
|
{
|
||||||
|
returnData.Add(new KeyValuePair<string, string>(item.Key, item.Value));
|
||||||
|
}
|
||||||
|
return returnData;
|
||||||
|
}
|
||||||
|
|
||||||
public bool SetData(string k, string v)
|
public bool SetData(string k, string v)
|
||||||
{
|
{
|
||||||
if (data.ContainsKey(k))
|
if (data.ContainsKey(k))
|
||||||
@ -173,7 +187,7 @@ public bool RemoveData(string k)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void OnLobbyDataUpdated(LobbyDataUpdate_t callback, bool error)
|
internal void OnLobbyDataUpdatedAPI(LobbyDataUpdate_t callback, bool error)
|
||||||
{
|
{
|
||||||
if(error) { return; }
|
if(error) { return; }
|
||||||
if(callback.SteamIDLobby == CurrentLobby) //actual lobby data was updated by owner
|
if(callback.SteamIDLobby == CurrentLobby) //actual lobby data was updated by owner
|
||||||
@ -198,13 +212,19 @@ internal void UpdateLobbyData()
|
|||||||
CurrentLobbyData.SetData(key, value);
|
CurrentLobbyData.SetData(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(OnLobbyDataUpdated != null) { OnLobbyDataUpdated(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Called when the lobby data itself has been updated. This callback is slower than the actual setting/getting of LobbyData, but it ensures safety.
|
||||||
|
public Action OnLobbyDataUpdated;
|
||||||
|
|
||||||
|
|
||||||
public Type LobbyType
|
public Type LobbyType
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (!IsValid) { return Type.None; } //if we're currently in a valid server
|
if (!IsValid) { return Type.Error; } //if we're currently in a valid server
|
||||||
|
|
||||||
//we know that we've set the lobby type via the lobbydata in the creation function
|
//we know that we've set the lobby type via the lobbydata in the creation function
|
||||||
//ps this is important because steam doesn't have an easy way to get lobby type (why idk)
|
//ps this is important because steam doesn't have an easy way to get lobby type (why idk)
|
||||||
@ -220,12 +240,12 @@ public Type LobbyType
|
|||||||
case "Public":
|
case "Public":
|
||||||
return Type.Public;
|
return Type.Public;
|
||||||
default:
|
default:
|
||||||
return Type.None;
|
return Type.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if(!IsValid) { return; }
|
if(!IsValid) { return; }
|
||||||
if(client.native.matchmaking.SetLobbyType(CurrentLobby, (SteamNative.LobbyType)value))
|
if(client.native.matchmaking.SetLobbyType(CurrentLobby, (SteamNative.LobbyType)value))
|
||||||
{
|
{
|
||||||
CurrentLobbyData.SetData("lobbytype", value.ToString());
|
CurrentLobbyData.SetData("lobbytype", value.ToString());
|
||||||
|
Loading…
Reference in New Issue
Block a user