Custom levels online ​
Each player on the main menu's Invite Friends chalkboard gets a status under their slot:
| Status | Who |
|---|---|
| green dot, On Swofty Launcher | you, couch players on your machine, and online players whose game runs Swofty Core |
| red dot, Not Using Swofty Launcher, Things may break | online players without Swofty Core |
A new online player shows no status for up to 3 seconds while Steam delivers their details.
When the host plays a custom level, every Swofty player in the lobby loads it too. Players without Swofty Launcher load the original kitchen, so the host gets a warning first:
Custom level
Some players aren't on Swofty Launcher. Things may break.
[PLAY ANYWAY] [CANCEL]Cancel is the default. Ask those players to start Overcooked 2 from Swofty Launcher.
Levels with addons ​
A level that lists addons starts only when every player has the host's copy of each one loaded: the same id, version and files. There is no Play anyway.
Can't start
Sam isn't on Swofty Launcher, and this level needs addons.Missing addons
Kai: Taco Stand 1.0.0, Space Diner 1.2.0
Alex: Taco Stand 1.0.0 (has 1.1.0)
They can get them from Discover in Swofty Launcher, or from the level's description.Each player who is missing something gets their own dialog, and their launcher shows the addons with links to Discover:
Missing addons
Swofty wants to play Taco Tuesday. You need:
Taco Stand 1.0.0
Get them from Discover in Swofty Launcher, or from the level's description.Until the level starts, the chalkboard shows Missing addons under each player who still needs something. An addon installed while the game runs loads straight away, the line goes, and the host can start the level again.
How the level travels ​
Swofty Core uses the Steam lobby the game already makes for online play.
- Every Swofty player sets lobby member data
swoftyto{"core":"<version>","addons":[{"id":"...","version":"...","sha":"..."}]}, listing every loaded addon.shais the first 16 hex digits of a SHA-256 over the addon folder's files, hidden files left out. - The host puts the level's SHA-256 in lobby data
swofty.level.sha. A level up to 4000 bytes goes in lobby dataswofty.leveltoo. Steam keeps about 8 KB of lobby data in all, so a bigger level goes to each Swofty guest as one reliable Steam P2P packet on channel 5. - Each Swofty guest checks the SHA-256 and answers in member data
swofty.ack: the SHA-256 when it can play the level,!<sha> <reason>when it can't. - The host sends the level load once every Swofty guest has answered. Each guest applies the level before the game links the kitchen's objects, so the objects match on every machine.
When a level with addons can't start, the host also sets lobby data swofty.level.blocked to <attempt> <level id>, which tells each guest to check its own addons.
A guest that can't read the level, or doesn't answer within 15 seconds, stops the start:
10:58:12 [core] custom level a1b2c3d4e5f6 refused: Sam can't load this level: unknown kind "oven"The launcher gets the result in the session outbox:
{"event": "level_started", "id": "a1b2c3d4e5f6", "online": true, "players": 3, "swofty_players": 3}
{"event": "level_refused", "id": "a1b2c3d4e5f6", "reason": "Two players aren't on Swofty Launcher"}
{"event": "need_addons", "for": "lobby", "level": "a1b2c3d4e5f6", "addons": [{"id": "swofty.taco-stand", "version": "1.0.0"}]}need_addons comes from a guest's core when the host's level needs addons it doesn't have.
A level is at most 512 KB of JSON.
Instructions ​
A level's instructions show on every Swofty player's screen. The host turns the pages: its hold, or the 15-second timer, turns the page for everyone with the game's own tutorial dismiss message. A guest that hears nothing for 35 seconds turns the page itself.
Lobby in addons ​
using Swofty.Overcooked2;
namespace WhoIsHere
{
public sealed class WhoIsHere : IAddon
{
public void Load(AddonContext ctx)
{
Lobby.Changed += () =>
{
if (!Lobby.Online)
{
ctx.Log.Info("offline");
return;
}
foreach (LobbyMember m in Lobby.Members)
ctx.Log.Info(m.Name + (m.IsHost ? " (host)" : "") + (m.OnSwofty ? " on Swofty " + m.CoreVersion : " not on Swofty"));
};
}
}
}public static class Lobby
{
public static bool Online { get; }
public static bool IsHost { get; }
public static IList<LobbyMember> Members { get; }
public static event System.Action Changed;
public static bool Send(string kind, string data);
public static event System.Action<LobbyMessage> Received;
}
public sealed class LobbyMessage
{
public string Kind { get; }
public string Data { get; }
public ulong FromSteamId { get; }
public string FromName { get; }
}
public sealed class LobbyMember
{
public ulong SteamId { get; }
public string Name { get; }
public bool IsLocal { get; }
public bool IsHost { get; }
public bool OnSwofty { get; }
public string CoreVersion { get; }
}Online: the game is in a Steam lobby, as host or guest.Members: one entry per Steam account, yours included. Empty when offline. Couch players share their machine's entry.Changed: someone joined or left, a member's Swofty status changed, or the game went online or offline.CoreVersion: the member's Swofty Core version, ornullwhenOnSwoftyis false.Send: sendsdatato every other Swofty player in the lobby. Startkindwith your addon id, for examplemy.addon/emote. A message is at most about 4 KB, andSendreturns false when the game isn't online.Received: a message another Swofty player sent withSend. Players not on Swofty Launcher never see these messages.
Lobby.Received += m =>
{
if (m.Kind == "my.addon/emote")
ctx.Log.Info(m.FromName + " says " + m.Data);
};
Lobby.Send("my.addon/emote", "hello");Messages go over Steam P2P channel 6, guest to host and host to every Swofty guest, as UTF-8 text:
SWOFTYEV1
<kind>
<sender's Steam id>
<data>