Files
sbox-public/engine/Sandbox.Engine/Game/PartyRoom/PartyRoom.Message.cs
Sol Williams 745c9b46ff Party interface refresh (#4611)
* Rework party ux, create one implicitly when you go to invite somebody

* Flip it, friends on the left, party deck under your avatar

* Tidy up css, make big avatar styles all match

* Add PositionMode.AboveRight, fix party menu alignment

* Chat style tweaks

* PartyMenu tweaks, show max members

* Toast when party creation fails

* Push scope on events, let you talk to yourself

* Voice chat in parties again

* Flip the footer back

* Minor tweaks

* fmt

* adjust doc
2026-04-22 20:36:56 +01:00

86 lines
1.7 KiB
C#

using Sandbox.Engine;
namespace Sandbox;
partial class PartyRoom
{
const int ProtocolIdentity = 5084;
enum MessageIdentity : long
{
ChatMessage = 1001,
VoiceMessage = 1002,
Kicked = 1003,
}
public void SendChatMessage( string text )
{
using var bs = ByteStream.Create( 128 );
bs.Write( ProtocolIdentity );
bs.Write( MessageIdentity.ChatMessage );
bs.Write( text );
steamLobby.SendChatData( bs.ToArray() );
}
/// <summary>
/// Kick a member from the lobby. Only the owner can kick members.
/// </summary>
public void Kick( SteamId friend )
{
if ( !Owner.IsMe )
return;
using var bs = ByteStream.Create( 128 );
bs.Write( ProtocolIdentity );
bs.Write( MessageIdentity.Kicked );
bs.Write( friend );
steamLobby.SendChatData( bs.ToArray() );
}
void ILobby.OnMemberMessage( Friend friend, ByteStream stream )
{
var protocol = stream.Read<int>();
if ( protocol != ProtocolIdentity )
{
Log.Warning( $"Unknown Protocol from {friend}" );
return;
}
var ident = stream.Read<MessageIdentity>();
if ( ident == MessageIdentity.ChatMessage )
{
var contents = stream.Read<string>();
Log.Info( $"[Party] {friend}: {contents}" );
OnChatMessage?.Invoke( friend, contents );
using ( GlobalContext.MenuScope() )
{
Event.EventSystem.RunInterface<IEventListener>( x => x.OnChatMessage( friend, contents ) );
}
return;
}
else if ( ident == MessageIdentity.Kicked )
{
var kicked = new Friend( stream.Read<ulong>() );
if ( !kicked.IsMe )
return;
if ( friend.Id != Owner.Id )
return;
// kicked, leave the lobby
Leave();
return;
}
Log.Warning( $"Unhandled message from {friend}" );
}
}