From f89b69da95a43e08cf75de4467b89d97327db49e Mon Sep 17 00:00:00 2001 From: Kyle Johnsen Date: Wed, 2 Feb 2022 23:28:01 -0500 Subject: [PATCH] added test for getroomdata --- Runtime/VelNetManager.cs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Runtime/VelNetManager.cs b/Runtime/VelNetManager.cs index eca991a..903cdf6 100644 --- a/Runtime/VelNetManager.cs +++ b/Runtime/VelNetManager.cs @@ -24,7 +24,8 @@ namespace VelNet MASTER_MESSAGE = 4, YOU_JOINED = 5, PLAYER_LEFT = 6, - YOU_LEFT = 7 + YOU_LEFT = 7, + ROOM_DATA = 8 } public enum MessageSendType { @@ -36,7 +37,8 @@ namespace VelNet MESSAGE_OTHERS = 3, MESSAGE_ALL = 4, MESSAGE_GROUP = 5, - MESSAGE_SETGROUP = 6 + MESSAGE_SETGROUP = 6, + MESSAGE_GETROOMDATA = 9 }; public enum MessageType : byte @@ -616,6 +618,20 @@ namespace VelNet AddMessage(m); break; } + case MessageReceivedType.ROOM_DATA: + { + int N = GetIntFromBytes(ReadExact(stream, 4)); //the number of client datas to read + for(int i = 0; i < N; i++) + { + //client id + short string + int client_id = GetIntFromBytes(ReadExact(stream, 4)); + int s = stream.ReadByte(); + byte[] utf8data = ReadExact(stream, s); //the room name, encoded as utf-8 + string username = Encoding.UTF8.GetString(utf8data); + Debug.Log(username); + } + break; + } //joined case MessageReceivedType.PLAYER_JOINED: { @@ -820,7 +836,7 @@ namespace VelNet public static void GetRooms(Action callback = null) { - SendTcpMessage(new byte[] { 1 }); // very simple message + SendTcpMessage(new byte[] { (byte)MessageSendType.MESSAGE_GETROOMS }); // very simple message if (callback != null) { @@ -834,6 +850,18 @@ namespace VelNet } } + public static void GetRoomData(string roomname) + { + MemoryStream stream = new MemoryStream(); + BinaryWriter writer = new BinaryWriter(stream); + + byte[] R = Encoding.UTF8.GetBytes(roomname); + writer.Write((byte)MessageSendType.MESSAGE_GETROOMDATA); + writer.Write((byte)R.Length); + writer.Write(R); + SendTcpMessage(stream.ToArray()); + } + /// /// Joins a room by name ///