mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-19 01:27:51 -05:00
feat: two worlds, rooms of 40, random spawn with space
- rooms hold 40 players. a player not starting in their den arrives in a random room of config.spawnRooms that has space (AJ_SPAWN_ROOMS overrides); with every one full, the emptiest, over the cap. - two worlds, Aldan and Congo (AJ_WORLDS sets how many): each its own copy of every land, dens and parties shared. a player arrives in a random world with space and keeps it through dens and parties. - the settings menu's World row is back: the server sends the worlds' names (generic list 16) and the world list (rm), and the client asks for the names once at login. a buddy's "go to" leads into their world, whose name the buddy card shows. "Find Open World" (on by default) joins a full room in a world with space. - the panels show the world with the room. the test harness pins one world and the township. buildVersion 60.
This commit is contained in:
1 parent
b813d89cfa
commit
31cbd87ff8
7 files changed
+161
-25
No files matched your search
+116
-14
@@ -42,6 +42,14 @@ const {CURRENCIES, DIAMOND_TYPES, activeAvatar, avatarById, activePet, equippedB
|
||||
|
||||
const GENERIC_LIST_AVATARS = 64;
|
||||
const GENERIC_LIST_NEWSPAPER = 627;
|
||||
// the worlds' names (ServerSelector.getShardName): localization ids, the
|
||||
// game's own river names, world N being the Nth.
|
||||
const GENERIC_LIST_WORLD_NAMES = 16;
|
||||
const WORLD_NAME_IDS = Array.from({length: 29}, (_, i) => 551 + i);
|
||||
// the settings menu's "Find Open World" switch (gui.MySettings
|
||||
// SETTINGS_AUTO_SERVER_TRAVEL): a set bit is off. on, a room that is full in
|
||||
// the player's world is joined in another world that has space.
|
||||
const SETTING_FIND_OPEN_WORLD = 3;
|
||||
const USER_VAR_NEWSPAPER_READ = 455;
|
||||
const USER_VAR_GEM_BONUS = 214;
|
||||
// not one of the game's: the patched client's "hide blocked players" setting
|
||||
@@ -137,6 +145,19 @@ const THEME_PATH_PREFIX = "theme_"; // lib/http.js looks for this
|
||||
const chatLines = limits.limiter(config.chatLinesPerWindow, config.chatWindowMs);
|
||||
const online = new Map(); // lowercased username -> session
|
||||
const rooms = new Map(); // "path.name#shard" -> room
|
||||
|
||||
// worlds (config.shards): a land room's name ends in "#<world>"; dens,
|
||||
// parties and adventures have none and belong to no world. each player has
|
||||
// a world (session.worldId), picked when they arrive and changed by walking
|
||||
// into a room of another.
|
||||
const worldOf = name => {
|
||||
const found = /#(\d+)$/.exec(name || "");
|
||||
return found && config.shards.some(shard => shard.id === Number(found[1])) ? Number(found[1]) : 0;
|
||||
};
|
||||
const worldName = id => (config.shards.find(shard => shard.id === id) || {name: `World ${id}`}).name;
|
||||
const inWorld = id => [...online.values()].filter(session => session.worldId === id);
|
||||
const findOpenWorld = account => !((Number((account.userVars || {})[USER_VAR_SETTINGS]) >> SETTING_FIND_OPEN_WORLD) & 1)
|
||||
|| Number((account.userVars || {})[USER_VAR_SETTINGS]) < 0;
|
||||
let nextRoomId = 100;
|
||||
|
||||
const others = session => session.room ? [...session.room.sessions].filter(s => s !== session) : [];
|
||||
@@ -618,6 +639,23 @@ const handlers = {
|
||||
// defPack. list contents live on the official servers, so apart from the two
|
||||
// kinds that can be rebuilt from defPacks every list is answered empty; that
|
||||
// still releases whatever the client had waiting on it.
|
||||
// the settings menu's world list (ServerSelector, GamePlay.showServerSelectorMore):
|
||||
// a node's name, then each world as id, language, how full (0 to 4, 4
|
||||
// being full) and how many of the player's buddies are in it. the game
|
||||
// leaves out the world the player is in.
|
||||
rm(session) {
|
||||
const fields = [];
|
||||
const capacity = config.spawnRooms.length * config.maxUsersPerRoom;
|
||||
for (const shard of config.shards) {
|
||||
const here = inWorld(shard.id);
|
||||
const full = config.spawnRooms.every(base => roomFull(`${base}#${shard.id}`));
|
||||
const bars = full ? 4 : Math.min(3, Math.ceil(4 * here.length / capacity));
|
||||
const buddyCount = here.filter(other => session.account.buddies.includes(other.account.username.toLowerCase())).length;
|
||||
fields.push(shard.id, LANG_ENG, bars, buddyCount);
|
||||
}
|
||||
session.sendXt("rm", -1, "burrow", ...fields);
|
||||
},
|
||||
|
||||
gl(session, roomId, [listId]) {
|
||||
if (Number(listId) === GENERIC_LIST_NEWSPAPER) {
|
||||
// the client decides whether to pop the newspaper open when this list
|
||||
@@ -635,6 +673,9 @@ const handlers = {
|
||||
if (Number(listId) === GENERIC_LIST_AVATARS) {
|
||||
entries = defpacks.avatarTypes();
|
||||
}
|
||||
else if (Number(listId) === GENERIC_LIST_WORLD_NAMES) {
|
||||
entries = WORLD_NAME_IDS;
|
||||
}
|
||||
else if (defpacks.patternList(listId)) {
|
||||
entries = defpacks.patternList(listId);
|
||||
}
|
||||
@@ -929,7 +970,9 @@ const context = {
|
||||
tell: (...args) => tell(...args),
|
||||
leaveRoom: (...args) => leaveRoom(...args),
|
||||
ask: (...args) => ask(...args),
|
||||
travel: (session, base) => joinRoom(session, `${base}#${config.shards[0].id}`),
|
||||
travel: (session, base) => joinRoom(session, `${base}#${session.worldId || config.shards[0].id}`),
|
||||
worldOf,
|
||||
worldName,
|
||||
joinRoom: (...args) => joinRoom(...args),
|
||||
reloadRoom: session => reloadRoom(session),
|
||||
buyAgain: session => handlers[session.lastPurchase.cmd](session, session.lastPurchase.roomId, session.lastPurchase.params),
|
||||
@@ -1106,8 +1149,11 @@ const enterRoom = (session, name, base, displayName, shardId, props = {}) => {
|
||||
if (room && room === session.room) {
|
||||
return;
|
||||
}
|
||||
// moderators (marked so in the admin panel) are let into a full room.
|
||||
if (room && room.sessions.size >= config.maxUsersPerRoom && !session.account.moderator) {
|
||||
// moderators (marked so in the admin panel) are let into a full room, and
|
||||
// so is a player arriving when every spawn room is full (spawnRoom).
|
||||
const overflow = session.spawnOverflow;
|
||||
session.spawnOverflow = false;
|
||||
if (room && room.sessions.size >= config.maxUsersPerRoom && !session.account.moderator && !overflow) {
|
||||
joinFailed(session, "This room is currently full");
|
||||
return;
|
||||
}
|
||||
@@ -1120,6 +1166,13 @@ const enterRoom = (session, name, base, displayName, shardId, props = {}) => {
|
||||
}
|
||||
room.sessions.add(session);
|
||||
session.room = room;
|
||||
// a land room is in a world, which is the player's now; a den or a party
|
||||
// is in none, and the game is told the world the player was in, which it
|
||||
// goes back to when they walk out (RoomManagerWorld.shardId).
|
||||
if (worldOf(name)) {
|
||||
session.worldId = worldOf(name);
|
||||
}
|
||||
const worldId = session.worldId || shardId;
|
||||
if (props.denOwner && props.denOwner !== session.account) {
|
||||
noteDenVisit(props.denOwner, session.account);
|
||||
}
|
||||
@@ -1141,7 +1194,7 @@ const enterRoom = (session, name, base, displayName, shardId, props = {}) => {
|
||||
avatar.petInvId,
|
||||
LANG_ENG,
|
||||
room.customMusicDef,
|
||||
shardId);
|
||||
worldId);
|
||||
dens.sendRoomProperties(session, roomAsSeenBy(session, room));
|
||||
|
||||
for (const other of others(session)) {
|
||||
@@ -1153,8 +1206,8 @@ const enterRoom = (session, name, base, displayName, shardId, props = {}) => {
|
||||
};
|
||||
|
||||
const sendHome = session => {
|
||||
const shard = config.shards[0];
|
||||
enterRoom(session, `${config.startupRoom}#${shard.id}`, config.startupRoom, roomInfo.name(config.startupRoom), shard.id);
|
||||
const shard = session.worldId || config.shards[0].id;
|
||||
enterRoom(session, `${config.startupRoom}#${shard}`, config.startupRoom, roomInfo.name(config.startupRoom), shard);
|
||||
};
|
||||
|
||||
const emptyRoom = name => {
|
||||
@@ -1216,6 +1269,37 @@ const onUnblocked = (session, target) => {
|
||||
}
|
||||
};
|
||||
|
||||
// a world for a player arriving: one at random of those whose spawn rooms
|
||||
// are not all full; with every one full, the emptiest.
|
||||
const pickWorld = () => {
|
||||
const open = config.shards.filter(shard => config.spawnRooms.some(base => !roomFull(`${base}#${shard.id}`)));
|
||||
if (open.length > 0) {
|
||||
return open[Math.floor(Math.random() * open.length)].id;
|
||||
}
|
||||
return config.shards.reduce((emptiest, shard) => (inWorld(shard.id).length < inWorld(emptiest.id).length ? shard : emptiest)).id;
|
||||
};
|
||||
|
||||
const roomFull = name => {
|
||||
const room = rooms.get(name);
|
||||
return Boolean(room) && room.sessions.size >= config.maxUsersPerRoom;
|
||||
};
|
||||
|
||||
// a spawn room (config.spawnRooms) at random, of those with space; with
|
||||
// all of them full, the emptiest, which lets this player in over the cap.
|
||||
const spawnRoom = (session, shardId) => {
|
||||
const known = config.spawnRooms.filter(base => defpacks.roomDef(base));
|
||||
if (known.length === 0) {
|
||||
return config.startupRoom;
|
||||
}
|
||||
const open = known.filter(base => !roomFull(`${base}#${shardId}`));
|
||||
if (open.length > 0) {
|
||||
return open[Math.floor(Math.random() * open.length)];
|
||||
}
|
||||
const size = base => (rooms.get(`${base}#${shardId}`) || {sessions: new Set()}).sessions.size;
|
||||
session.spawnOverflow = true;
|
||||
return known.reduce((emptiest, base) => (size(base) < size(emptiest) ? base : emptiest));
|
||||
};
|
||||
|
||||
const joinRoom = (session, requested) => {
|
||||
// "jamaa_township.room_main#-1": path, then shard (-1 = pick one for me).
|
||||
let [base, shardText] = requested.split("@")[0].split("#");
|
||||
@@ -1240,23 +1324,41 @@ const joinRoom = (session, requested) => {
|
||||
// non-buddy's until then: it is sent ahead of the first room, as the
|
||||
// client takes it unasked (BuddyManager.buddyListResponseHandler).
|
||||
handlers.bl(session);
|
||||
// the game asks for world -1 ("pick one for me") unless it is going back
|
||||
// to one (after a reconnect, say).
|
||||
session.worldId = worldOf(`#${shardText}`) || pickWorld();
|
||||
const {startInDen, startRoom, username} = session.account;
|
||||
const den = startInDen ? username : /^den/i.test(startRoom || "") ? startRoom.slice(3) : null;
|
||||
if (den !== null && accounts.byName(den)) {
|
||||
joinDen(session, `den${den}`);
|
||||
return;
|
||||
}
|
||||
// any other name asked for that is a room here; else the usual one.
|
||||
// any other name asked for that is a room here and has space; else one
|
||||
// of the spawn rooms that has, so nobody's login ends at "room is full".
|
||||
const asked = (startRoom || "").split("#")[0].toLowerCase();
|
||||
if (!startInDen && defpacks.roomDef(asked) && !asked.startsWith("den")) {
|
||||
base = asked;
|
||||
}
|
||||
const shardId = session.worldId;
|
||||
base = !startInDen && defpacks.roomDef(asked) && !asked.startsWith("den") && !roomFull(`${asked}#${shardId}`)
|
||||
? asked : spawnRoom(session, shardId);
|
||||
shardText = String(shardId);
|
||||
}
|
||||
// switching worlds (the settings menu's world list asks for the township of
|
||||
// the one picked): a full room there is swapped for one with space.
|
||||
else if (worldOf(`#${shardText}`) && session.worldId && worldOf(`#${shardText}`) !== session.worldId
|
||||
&& roomFull(`${base}#${shardText}`) && config.spawnRooms.includes(base)) {
|
||||
base = spawnRoom(session, Number(shardText));
|
||||
}
|
||||
if (!defpacks.roomDef(base) || base.startsWith("den")) {
|
||||
joinFailed(session, `Room "${requested}" is not supported by this server`);
|
||||
return;
|
||||
}
|
||||
const shard = config.shards.find(s => s.id === Number(shardText)) || config.shards[0];
|
||||
// a world that is not one here (-1, or one the game made up because every
|
||||
// world was full) is the player's own.
|
||||
let shard = config.shards.find(s => s.id === Number(shardText)) || config.shards.find(s => s.id === session.worldId) || config.shards[0];
|
||||
// full there: with "Find Open World" on, the same room in a world that
|
||||
// has space (moderators get into a full room anyway).
|
||||
if (roomFull(`${base}#${shard.id}`) && !session.account.moderator && findOpenWorld(session.account)) {
|
||||
shard = config.shards.find(other => !roomFull(`${base}#${other.id}`)) || shard;
|
||||
}
|
||||
enterRoom(session, `${base}#${shard.id}`, base, roomInfo.name(base), shard.id);
|
||||
};
|
||||
|
||||
@@ -1268,7 +1370,7 @@ const joinDen = (session, requested) => {
|
||||
// room like any other (lib/epicdens.js). A player of that name comes first.
|
||||
const showcase = owner ? null : epicDens.byName(requested.slice(3));
|
||||
if (showcase) {
|
||||
const shard = config.shards[0].id;
|
||||
const shard = session.worldId || config.shards[0].id;
|
||||
enterRoom(session, `${showcase.base}#${shard}`, showcase.base, showcase.name, shard);
|
||||
return;
|
||||
}
|
||||
@@ -1587,7 +1689,7 @@ module.exports = {
|
||||
return "There is no such room";
|
||||
}
|
||||
minigames.leave(session);
|
||||
const shard = config.shards[0].id;
|
||||
const shard = session.worldId || config.shards[0].id;
|
||||
enterRoom(session, `${base}#${shard}`, base, roomInfo.name(base), shard);
|
||||
return null;
|
||||
},
|
||||
@@ -1627,7 +1729,7 @@ module.exports = {
|
||||
},
|
||||
players: () => [...online.values()].map(session => ({
|
||||
username: session.account.username,
|
||||
room: session.room ? session.room.name : null,
|
||||
room: session.room ? session.room.name.replace(/#(\d+)$/, (whole, id) => (worldOf(whole) ? ` (${worldName(Number(id))})` : whole)) : null,
|
||||
address: session.address,
|
||||
})),
|
||||
};
|
||||
Reference in new issue
Block a user