Client message

From pikdum/thistle_tea · View interactive version

Client message is an AI agent skill from the GitHub repository pikdum/thistle_tea. Implement Thistle Tea CMSG_* client messages following our architecture patterns. Use this when asked to implement a new message or you need to use one that isn't implemented yet.

How to use this skill

Skill file

A client message is one module under lib/game/inbound/ (ThistleTea.Game.Inbound.CmsgFoo) that both decodes its payload and handles the decoded struct by calling into the world.

The inbound layer sits above the world: it may call World, Core, Network, and Auth, but nothing below it may reference an inbound module. boundary rejects that at compile time. World code never names a client message; the player process applies one through the ThistleTea.Game.World.ClientInput protocol, which the use macro implements.

Module

Create or modify a module under lib/game/inbound/ that:

Then register the opcode in @messages in lib/game/inbound/dispatch.ex so packets decode into the struct.

The macro aliases ClientMessage, Message (server messages, ThistleTea.Game.Network.Message), BinaryUtils, and MovementBlock. Alias the world modules the handler calls yourself.

Use use ThistleTea.Game.Inbound.ClientMessage, opcode: :CMSG_FOO, while_possessed: true only for messages a player's client must still be able to send while another unit possesses the player. These are connection, chat, logout, cache query, and movement acknowledgement traffic. Everything else is suspended during possession.

A minimal payload, CMSG_GROUP_INVITE:

defmodule ThistleTea.Game.Inbound.CmsgGroupInvite do
  @moduledoc false
  use ThistleTea.Game.Inbound.ClientMessage, :CMSG_GROUP_INVITE

  alias ThistleTea.Game.World.Entity.Player.Groups

  defstruct [:name]

  @impl ClientMessage
  def from_binary(payload) do
    {:ok, name, _rest} = BinaryUtils.parse_string(payload)
    %__MODULE__{name: name}
  end

  @impl ClientMessage
  def handle(%__MODULE__{name: name}, state), do: Groups.invite(state, name)
end

A payload with strings, from CMSG_MESSAGECHAT:

def from_binary(payload) do
  <<chat_type::little-size(32), language::little-size(32), rest::binary>> = payload
  {:ok, message, _rest} = BinaryUtils.parse_string(rest)

  %__MODULE__{
    chat_type: chat_type,
    language: language,
    message: message
  }
end

Handling

How to find the packet spec

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.