mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 14:15:47 +03:00
Added OnChatStringRecieved, cleaned up OnLobbyChatMessageRecievedAPI
This commit is contained in:
parent
d959dafae0
commit
54dab0c2a4
@ -273,6 +273,12 @@ public void SendChatMessage()
|
|||||||
Assert.IsTrue(message == testString);
|
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);
|
client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);
|
||||||
|
|
||||||
var sw = Stopwatch.StartNew();
|
var sw = Stopwatch.StartNew();
|
||||||
|
@ -318,28 +318,24 @@ public Type LobbyType
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static byte[] chatMessageData = new byte[1024 * 4];
|
||||||
|
|
||||||
private unsafe void OnLobbyChatMessageRecievedAPI(LobbyChatMsg_t callback, bool error)
|
private unsafe void OnLobbyChatMessageRecievedAPI(LobbyChatMsg_t callback, bool error)
|
||||||
{
|
{
|
||||||
//from Client.Networking
|
//from Client.Networking
|
||||||
if(error || callback.SteamIDLobby != CurrentLobby) { return; }
|
if(error || callback.SteamIDLobby != CurrentLobby)
|
||||||
|
return;
|
||||||
|
|
||||||
byte[] ReceiveBuffer = new byte[1024];
|
|
||||||
SteamNative.CSteamID steamid = 1;
|
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;
|
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);
|
readData = client.native.matchmaking.GetLobbyChatEntry(CurrentLobby, (int)callback.ChatID, out steamid, (IntPtr)p, chatMessageData.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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
OnChatMessageRecieved?.Invoke(steamid, chatMessageData, readData);
|
||||||
|
OnChatStringRecieved?.Invoke(steamid, Encoding.UTF8.GetString(chatMessageData));
|
||||||
if (OnChatMessageRecieved != null) { OnChatMessageRecieved(steamid, ReceiveBuffer, readData); }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -347,6 +343,11 @@ private unsafe void OnLobbyChatMessageRecievedAPI(LobbyChatMsg_t callback, bool
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Action<ulong, byte[], int> OnChatMessageRecieved;
|
public Action<ulong, byte[], int> OnChatMessageRecieved;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Like OnChatMessageRecieved but the data is converted to a string
|
||||||
|
/// </summary>
|
||||||
|
public Action<ulong, string> OnChatStringRecieved;
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// 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>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user