Network protocol (Worms 2)
From Worms Knowledge Base
The Worms 2 servers host rooms in which users can meet to then connect to each other's PCs for playing games.
The following servers are hosted by Team17:
|Worms2 Server (UK)||uk1.servers.worms2.com||17000||"The Team17 Server". Started to reject new connections in July 2020, shortly after some Worms enthusiasts played on it. Unclear whether the sudden activity downed it, it did not immediately break. The client will display "Unable to create new player..." when attempting to connect to it.|
|Worms2 Demo Server (UK)||uk1.servers.worms2.com||17171||Server for Worms 2 demo. Allows full versions to connect aswell. Did not go down in July 2020.|
The server hosting the user, room, and game lists communicates with packets in the following format:
|0||uint32||4||Code||Determines the type of packet. Known packets are listed below.|
|4||uint32||4||Flags||A bitset determining which of the following fields will be available.|
|?||uint32||4||Value 0||If bit 0 is set in Flags.|
|?||uint32||4||Value 1||If bit 1 is set in Flags.|
|?||uint32||4||Value 2||If bit 2 is set in Flags.|
|?||uint32||4||Value 3||If bit 3 is set in Flags.|
|?||uint32||4||Value 4||If bit 4 is set in Flags. Never used other than client-side?|
|?||uint32||4||Value 10||If bit 10 is set in Flags.|
|?||uint32||4||Data Length||If bit 5 is set in Flags.|
|?||char[DataLength]||Data Length||Data||If bit 5 is set in Flags, stores Windows-1251 encoded text like an IP string or full chat message.|
|?||uint32||4||Error||If bit 7 is set in Flags. Returns a Windows error code from the server, like E_FAIL for when the name of a room to create contains a bad word.|
|?||char||20||Name||If bit 8 is set in Flags, stores a Windows-1251 encoded session name. Unused bytes are 0.|
|?||Session info||50||Session||If bit 9 is set in Flags. Unused bytes are 0.|
Several packets identify a user, room, or game with the Name and Session fields. The latter provides the following information:
|8||uint8||1||Nation / Flag|
|9||uint8||1||Game version, always 49|
|10||uint8||1||Game release (same as Game version, 50 if CD check failed)|
|11||uint8||1||Type (1=room, 4=game, 5=user)|
|12||uint8||1||Access (1=public, 2=protected)|
|15||gap||35||Unused, all 0.|
Passing other or invalid combinations (protected users and rooms do not exist, only passworded games) will display a French flag with the default state or a question mark in the UI.
The Worms 2 22.214.171.124 Demo uses significantly different values compared to the full version 126.96.36.199 patch, causing said question marks to appear. However, interactions with full version users still work.
Nation / Flag
Determines which flag is displayed with the user, room, or game. Two flags are custom (Skull and Team17) and are not normally selectable. Des patch can unlock the selection of them, and adds another entry for an "invalid" country code, creating an empty flag. Below, the flags are listed with the description displayed when hovering players.
|9||Bosnia||old flag of Bosnia and Herzegovina|
|49||United States of America|
|51||Worms2 Imperial Troopers||Team17 flag|
|other||Unknown||French flag for players, question mark for rooms|
Becomes 50 if CD detection failed. The CD detection consists of the following tests:
- Find CD drive, where drives A: and B: are ignored - a found drive letter is stored in the registry under HKCU\SOFTWARE\Team17SoftwareLTD\Worms2\CD. (error 2 otherwise)
- Check the CD being labeled "Worms 2", "WORMS2", or - for Trymedia 1.07 versions - "Worms2_bl". (error 1 otherwise)
- Check if the CD has no free space to ensure it being a CD-ROM. (error 3 otherwise)
- Check if the CD stores an "autorun.inf" file. (error 4 otherwise)
As specified above, the Code of a packet determines the Action to take on either the server or client side and in effect which fields are used. Some codes are reused for multiple occassions, and some are unused in the 188.8.131.52 patch.
Client query packets are also used for server notices, represented by the Type column in the following table:
- Query: A client query to execute an action on the server, always getting a reply (even codes only).
- Reply: A server reply to a client query, always reporting back an Error code, 0 for success (odd codes only).
- Notice: Same as query, but coming as an out-of-bound server packet to update the state on the client, like when another user joins or creates a game.
Note that the same ID counter is incremented for users (UID), rooms (RID), and games (GID) - if a user logs in with UID 0x1000 and immediately creates a room, the RID will be 0x1001. The counter should also start at a high enough value (0x1000 seems to work fine) to not cause duplicate chat messages appearing client-side, apparently because it is also reused as an index in some packets.
|Code||Action||Type||Value 0||Value 1||Value 2||Value 3||Value 4||Value 10||Data||Name / Session|
|350||List Item||Reply||UID / RID / GID||user / creator / host IP||user / room / game|
|600||Login||Notice||remote UID||0||remote user|
|700||Create Room||Query||0||0||creator IP||room|
|700||Create Room||Notice||new RID||0||creator IP||room|
|701||Create Room||Reply||new RID|
|800||Join Room / Game||Query||joined RID / GID||local UID|
|800||Join Room / Game||Notice||joined RID / GID||remote UID|
|801||Join Room / Game||Reply|
|900||Leave Room / Game||Query||left RID / GID||local UID|
|900||Leave Room / Game||Notice||left RID / GID||remote UID|
|901||Leave Room / Game||Reply|
|1000||Disconnect User||Query||local UID|
|1000||Disconnect User||Notice||remote UID|
|1100||Close Room / Game||Query||RID / GID|
|1100||Close Room / Game||Notice||RID / GID|
|1101||Close Room / Game||Reply|
|1200||Create Game||Query||0||RID||0x800||host IP||host|
|1200||Create Game||Notice||GID||RID||0x800||host IP||host|
|1300||Room Chat||Query||local UID||receiver RID / UID||"GRP:[ UserName ] Message" / "PRV:[ UserName ] Message"|
|1300||Room Chat||Notice||remote UID||receiver RID / UID||"GRP:[ UserName ] Message" / "PRV:[ UserName ] Message"|
|1327||Connect Game||Reply||host IP|
- Only ever sent as a notice by the server, clients disconnect without any query and awaited reply.
- Since the host reports its incorrectly detected NAT IP here, Worms 2 Memory Changer has to be used to inject the actual IP address into Worms 2 before creating a room.
- Original server always reports E_FAIL in error code, even though messages were sent.
Game room communication
The players are connected via P2P using DirectPlay. This means the ports 47624 (for the lobby connection itself) and 2300 to 2400 (for each player connection) should be forwarded in any router. The fact that each player is connected to another means that the host can leave the game at any time, the remaining players can continue playing without dropping, unlike in Worms Armageddon or Worms World Party.