Added OnChatStringRecieved, cleaned up OnLobbyChatMessageRecievedAPI

This commit is contained in:
Garry Newman 2017-12-06 11:25:30 +00:00
parent d959dafae0
commit 54dab0c2a4
2 changed files with 20 additions and 13 deletions

View File

@ -273,6 +273,12 @@ public void SendChatMessage()
Assert.IsTrue(message == testString);
};
client.Lobby.OnChatStringRecieved = (steamID, message) =>
{
Console.WriteLine("message recieved");
Assert.IsTrue(message == testString);
};
client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);
var sw = Stopwatch.StartNew();

View File

@ -318,28 +318,24 @@ public Type LobbyType
}
}
private static byte[] chatMessageData = new byte[1024 * 4];
private unsafe void OnLobbyChatMessageRecievedAPI(LobbyChatMsg_t callback, bool error)
{
//from Client.Networking
if(error || callback.SteamIDLobby != CurrentLobby) { return; }
if(error || callback.SteamIDLobby != CurrentLobby)
return;
byte[] ReceiveBuffer = new byte[1024];
SteamNative.CSteamID steamid = 1;
ChatEntryType chatEntryType; //not used
ChatEntryType chatEntryType; // "If set then this will just always return k_EChatEntryTypeChatMsg. This can usually just be set to NULL."
int readData = 0;
fixed (byte* p = ReceiveBuffer)
fixed (byte* p = chatMessageData)
{
readData = client.native.matchmaking.GetLobbyChatEntry(CurrentLobby, (int)callback.ChatID, out steamid, (IntPtr)p, ReceiveBuffer.Length, out chatEntryType);
while (ReceiveBuffer.Length < readData)
{
ReceiveBuffer = new byte[readData + 1024];
readData = client.native.matchmaking.GetLobbyChatEntry(CurrentLobby, (int)callback.ChatID, out steamid, (IntPtr)p, ReceiveBuffer.Length, out chatEntryType);
}
readData = client.native.matchmaking.GetLobbyChatEntry(CurrentLobby, (int)callback.ChatID, out steamid, (IntPtr)p, chatMessageData.Length, out chatEntryType);
}
if (OnChatMessageRecieved != null) { OnChatMessageRecieved(steamid, ReceiveBuffer, readData); }
OnChatMessageRecieved?.Invoke(steamid, chatMessageData, readData);
OnChatStringRecieved?.Invoke(steamid, Encoding.UTF8.GetString(chatMessageData));
}
/// <summary>
@ -347,6 +343,11 @@ private unsafe void OnLobbyChatMessageRecievedAPI(LobbyChatMsg_t callback, bool
/// </summary>
public Action<ulong, byte[], int> OnChatMessageRecieved;
/// <summary>
/// Like OnChatMessageRecieved but the data is converted to a string
/// </summary>
public Action<ulong, string> OnChatStringRecieved;
/// <summary>
/// Broadcasts a chat message to the all the users in the lobby users in the lobby (including the local user) will receive a LobbyChatMsg_t callback.
/// </summary>