From 30eb23ffe5f7b9e8c3b4267457d0aa3bd02665e7 Mon Sep 17 00:00:00 2001 From: hovertank3d Date: Mon, 23 Feb 2026 23:17:56 +0100 Subject: implement `connect`, `disconnect` and `accept` --- PROTOCOL.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'PROTOCOL.md') diff --git a/PROTOCOL.md b/PROTOCOL.md index 3bf9358..a0dd433 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -7,9 +7,9 @@ this should suffice as a starting point. | id | direction | captured | known | packet name | short description | |-|-|-|-|-|-| | 0 | | ☐ | ☐ | | | -| 1 | c->s | ☑ | ☐ | | | -| 2 | | ☐ | ☐ | | | -| 3 | c<-s | ☑ | ☐ | | | +| 1 | c->s | ☑ | ☑ | connect | login initialization | +| 2 | s->c | ☑ | ☑ | disconnect | kick client | +| 3 | c<-s | ☑ | ☑ | accept | accept connection | | 4 | c->s | ☑ | ☐ | | | | 5 | c->s | ☑ | ☐ | | | | 6 | c->s | ☑ | ☐ | | | @@ -261,4 +261,60 @@ this should suffice as a starting point. | 252 | | ☐ | ☐ | | | | 253 | | ☐ | ☐ | | | | 254 | | ☐ | ☐ | | | -| 255 | | ☐ | ☐ | | | \ No newline at end of file +| 255 | | ☐ | ☐ | | | + + +## `id 1` `c->s` connect + +| name | type | size | description | +|--|--|--|--| +| version | pstring | - | terraria protocol version in form of "TerrariaXXX" | + +ilspy decompilation: +```csharp + // Terraria.NetMessage.SendData + case 1: + writer.Write("Terraria" + 318); + break; +``` + +## `id 2` `s->c` disconnect +kick client from server. server closes connection right after sending this + +| name | type | size | description | +|--|--|--|--| +| reason | netstring | - | reason for kicking. may be ban, invalid client version, etc. | + +ilspy decompilation: +```csharp + // Terraria.NetMessage.SendData + case 2: + text.Serialize(writer); + if (Main.dedServ) + { + Console.WriteLine(Language.GetTextValue("CLI.ClientWasBooted", Netplay.Clients[num].Socket.GetRemoteAddress().ToString(), text)); + } + break; +``` + +## `id 3` `s->c` accept +accept client connection, pick new (player) slot id and send server flags + +| name | type | size | description | +|--|--|--|--| +| slot | uint8_t | 1 | player id | +| server_flags | uint8_t | 1 | flags, always 0 | + +ilspy decompilation: +```csharp + // Terraria.NetMessage.SendData + case 3: + writer.Write((byte)remoteClient); + writer.Write(value: false); + break; + + // Terraria.MessageBuffer.GetData + int num95 = reader.ReadByte(); + bool value2 = reader.ReadBoolean(); + Netplay.Connection.ServerSpecialFlags[2] = value2; +``` \ No newline at end of file -- cgit v1.2.3