Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/action/__action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "buy.hpp"

#include "quit.hpp"
#include "commands/trade.hpp"

#include "__action.hpp"

Expand All @@ -47,6 +48,11 @@ std::unordered_map<std::string, std::function<void(ENetEvent&, const std::string
{"action|info", std::bind(&action::info, std::placeholders::_1, std::placeholders::_2)},
{"action|trash", std::bind(&action::trash, std::placeholders::_1, std::placeholders::_2)},
{"action|wrench", std::bind(&action::wrench, std::placeholders::_1, std::placeholders::_2)},
{"action|trade_started", std::bind(&action::trade_started, std::placeholders::_1, std::placeholders::_2)},
{"action|mod_trade", std::bind(&action::mod_trade, std::placeholders::_1, std::placeholders::_2)},
{"action|rem_trade", std::bind(&action::rem_trade, std::placeholders::_1, std::placeholders::_2)},
{"action|trade_accept", std::bind(&action::trade_accept, std::placeholders::_1, std::placeholders::_2)},
{"action|trade_cancel", std::bind(&action::trade_cancel, std::placeholders::_1, std::placeholders::_2)},
{"action|itemfavourite", std::bind(&action::itemfavourite, std::placeholders::_1, std::placeholders::_2)},
{"action|inventoryfavuitrigger", std::bind(&action::inventoryfavuitrigger, std::placeholders::_1, std::placeholders::_2)},
{"action|store", std::bind(&action::store, std::placeholders::_1, std::placeholders::_2)},
Expand Down
3 changes: 2 additions & 1 deletion include/action/buy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void action::buy(ENetEvent& event, const std::string& header, const std::string_
});
return;
}
const auto base_items = shouhin.items; // @note keep the store.txt contents for the next purchase
std::vector<short> ids{};
if (shouhin.btn == "basic_splice") // @note source: https://growtopia.fandom.com/wiki/Basic_Splicing_Kit
{
Expand Down Expand Up @@ -132,7 +133,7 @@ void action::buy(ENetEvent& event, const std::string& header, const std::string_
else modify_item_inventory(event, {item.first, item.second});
received.append(std::format("{}, ", raw_name)); // @todo add green text to rare items, or something cool.
}
shouhin.items.clear(); // @todo
shouhin.items = base_items; // @note restore, so packs and backpack upgrades work every time

send_varlist(event.peer, { "OnStorePurchaseResult", (_tab < 5) ?
std::format(
Expand Down
29 changes: 29 additions & 0 deletions include/action/dialog_return/__dialog_return.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
#include "create_blast.hpp"
#include "socialportal.hpp"
#include "megaphone.hpp"
#include "commands/worldtools.hpp"
#include "commands/devmenu.hpp"
#include "commands/growscan.hpp"
#include "commands/jammers.hpp"
#include "commands/accounts.hpp"
#include "commands/staff.hpp"
#include "nuke_confirm.hpp"
#include "commands/cooking.hpp"
#include "commands/trade.hpp"
#include "commands/friendsys.hpp"
#include "commands/legendary.hpp"

#include "__dialog_return.hpp"

Expand All @@ -31,4 +42,22 @@ std::unordered_map<std::string, std::function<void(ENetEvent &, const ::hPipe &)
{"create_blast", std::bind(&create_blast, std::placeholders::_1, std::placeholders::_2)},
{"socialportal", std::bind(&socialportal, std::placeholders::_1, std::placeholders::_2)},
{"megaphone", std::bind(&megaphone, std::placeholders::_1, std::placeholders::_2)},
{"birth_certificate", std::bind(&birth_certificate_return, std::placeholders::_1, std::placeholders::_2)},
{"change_address", std::bind(&change_address_return, std::placeholders::_1, std::placeholders::_2)},
{"delete_all_worlds", std::bind(&delete_all_worlds_return, std::placeholders::_1, std::placeholders::_2)},
{"fill_world", std::bind(&fill_world_return, std::placeholders::_1, std::placeholders::_2)},
{"dev_menu", std::bind(&dev_menu_return, std::placeholders::_1, std::placeholders::_2)},
{"cmd_form", std::bind(&cmd_form_return, std::placeholders::_1, std::placeholders::_2)},
{"find_give", std::bind(&find_give_return, std::placeholders::_1, std::placeholders::_2)},
{"growscan", std::bind(&growscan_return, std::placeholders::_1, std::placeholders::_2)},
{"jammer_edit", std::bind(&jammer_edit_return, std::placeholders::_1, std::placeholders::_2)},
{"accounts", std::bind(&accounts_return, std::placeholders::_1, std::placeholders::_2)},
{"trade_add", std::bind(&trade_return, std::placeholders::_1, std::placeholders::_2)},
{"trade_confirm", std::bind(&trade_return, std::placeholders::_1, std::placeholders::_2)},
{"legendary_wizard", std::bind(&wizard_return, std::placeholders::_1, std::placeholders::_2)},
{"title_edit", std::bind(&titles_return, std::placeholders::_1, std::placeholders::_2)},
{"friend_request", std::bind(&friends_return, std::placeholders::_1, std::placeholders::_2)},
{"friends_list", std::bind(&friends_return, std::placeholders::_1, std::placeholders::_2)},
{"nuke_confirm", std::bind(&nuke_confirm, std::placeholders::_1, std::placeholders::_2)},
{"cooking_dialog", std::bind(&cooking_dialog, std::placeholders::_1, std::placeholders::_2)},
};
34 changes: 3 additions & 31 deletions include/action/dialog_return/create_blast.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
#include "pch.hpp"

#include "action/quit_to_exit.hpp" // @note peer leave world
#include "action/join_request.hpp" // @note peer enter (blast) world
#include "commands/blasts.hpp"

#include "create_blast.hpp"

void create_blast(ENetEvent& event, const ::hPipe &hPipe)
{
const int id = atoi(hPipe["id"].c_str());
std::string world_name = hPipe["name"];

for (char &c : world_name) c = std::toupper(c); // @note start -> START

switch (id)
{
case 1402: // @note Thermonuclear Blast
{
auto it = std::ranges::find(worlds, world_name, &::world::name);
if (it == worlds.end())
{
::world world{world_name}; // @note we don't need emplace into worlds since no one is in the world yet!

action::quit_to_exit(event, "", true);
blast::thermonuclear(world);
} // @note save the world and continue in action::join_request. seems tedious so i might change later.
else
{
/* @todo prompt saying world already exists. */
return;
}
break;
}
default: return;
}
action::join_request(event, "", world_name);
}
blast_create(event, atoi(hPipe["id"].c_str()), hPipe["name"]);
}
23 changes: 16 additions & 7 deletions include/action/dialog_return/find_item.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#include "pch.hpp"
#include "commands/devmenu.hpp"

#include "onVariant/SetClothing.hpp"

#include "commands/find.hpp"
#include "commands/legendary.hpp"
#include "find_item.hpp"

void find_item(ENetEvent& event, const ::hPipe &hPipe)
{
std::string id = readch(hPipe["buttonClicked"], '_')[1]; // e.g. searchableItemListButton_2_0_-1
if (id.empty()) return;

modify_item_inventory(event, ::slot(atoi(id.c_str()), 200));
}
const std::string btn = hPipe["buttonClicked"];
const bool staff = static_cast<::peer*>(event.peer->data)->role >= MODERATOR;
if (!btn.starts_with("searchableItemListButton_"))
{
if (!staff) find_players_list(event, hPipe["n"]); // @note the Search button (or Enter)
return;
}
const std::vector<std::string> parts = readch(btn, '_'); // e.g. searchableItemListButton_2_0_-1
if (parts.size() < 2 || parts[1].empty()) return;
const int id = atoi(parts[1].c_str());
if (!staff && staff_only_item(id)) return;
find_item_popup(event, id);
}
52 changes: 42 additions & 10 deletions include/action/dialog_return/lock_edit.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pch.hpp"
#include "onVariant/ConsoleMessage.hpp"

#include "database/world.hpp"
#include "commands/lockaccess.hpp"
#include "lock_edit.hpp"

void lock_edit(ENetEvent& event, const ::hPipe &hPipe)
Expand All @@ -13,22 +14,53 @@ void lock_edit(ENetEvent& event, const ::hPipe &hPipe)
::pos pos{};
pos.x = atoi(hPipe["tilex"].c_str());
pos.y = atoi(hPipe["tiley"].c_str());

world->is_public = atoi(hPipe["checkbox_public"].c_str());

::block &block = world->blocks[cord(pos.x, pos.y)];

/* "Get World Key" button: hand over the tradeable key item instead of
* toggling anything. only the owner (or staff) may take it. */
if (hPipe["buttonClicked"] == "getKey")
{
if (world->owner != pPeer->user_id && pPeer->role < MODERATOR)
{
on::ConsoleMessage(event.peer, "`4Only the world owner can take the World Key.``");
return;
}

modify_item_inventory(event, ::slot(242 /* World Key */, 1));
on::ConsoleMessage(event.peer,
std::format("`2You received a `$World Key`` for `w{}``.``", world->name));
return;
}

lock_access_apply(event, *world, hPipe); // @note access list: remove unchecked, add the picked player

if (atoi(hPipe["checkbox_disable_music"].c_str()) != 0)
world->lock_state |= DISABLE_MUSIC;
else world->lock_state &= ~DISABLE_MUSIC;
world->minimum_entry_level = atoi(hPipe["minimum_entry_level"].c_str());

::block &block = world->blocks[cord(pos.x, pos.y)];
world->minimum_entry_level = atoi(hPipe["minimum_entry_level"].c_str());

if (world->is_public)
block.state[2] |= S_PUBLIC;
else block.state[2] &= ~S_PUBLIC;
on::ConsoleMessage(event.peer, std::format("`2{}`` has set the `$World Lock`` to {}``", pPeer->growid, (block.state[2] & S_PUBLIC) ? "`$PUBLIC" : "`4PRIVATE"));
/* public/private is staff-only now - it lives behind /private instead */
const bool wants_public = atoi(hPipe["checkbox_public"].c_str()) != 0;
if (wants_public != static_cast<bool>(world->is_public))
{
if (pPeer->role < MODERATOR)
{
on::ConsoleMessage(event.peer,
"`4Use `$/private`` to change who can enter this world.``");
}
else
{
world->is_public = wants_public;
if (world->is_public)
block.state[2] |= S_PUBLIC;
else block.state[2] &= ~S_PUBLIC;
}
}

send_tile_update(event, {
.id = block.fg,
.punch = pos
}, block, *world);
}
}
17 changes: 13 additions & 4 deletions include/action/dialog_return/megaphone.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#include "pch.hpp"

#include "tools/bubble.hpp"
#include "onVariant/ConsoleMessage.hpp"
#include "commands/sb.hpp"

#include "megaphone.hpp"

void megaphone(ENetEvent& event, const ::hPipe &hPipe)
{
sb(event, hPipe["message"]); // @todo handle this when /sb requires gems @todo handle trim
}
::peer *pPeer = static_cast<::peer*>(event.peer->data);
if (pPeer->curse_until > std::time(nullptr))
{
tell(event.peer, "`4You can't do that while cursed.``");
return;
}

std::string message = hPipe["message"];
if (message.empty()) return;
sb(event, "sb " + message); // @note /sb skips the first 3 chars ("sb ")
}
60 changes: 60 additions & 0 deletions include/action/dialog_return/nuke_confirm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "pch.hpp"
#include "onVariant/ConsoleMessage.hpp"
#include "action/join_request.hpp"
#include "action/quit_to_exit.hpp"
#include "database/world.hpp"
#include "nuke_confirm.hpp"

void nuke_confirm(ENetEvent& event, const ::hPipe &hPipe)

Check warning on line 8 in include/action/dialog_return/nuke_confirm.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/action/dialog_return/nuke_confirm.cpp#L8

Method nuke_confirm has a cyclomatic complexity of 9 (limit is 8)
{
::peer *pPeer = static_cast<::peer*>(event.peer->data);

if (pPeer->role < DEVELOPER) return;
if (pPeer->netid == 0) return;

auto world = std::ranges::find(worlds, pPeer->recent_worlds.back(), &::world::name);
if (world == worlds.end()) return;

const std::string world_name = world->name;

blast::thermonuclear(*world);
world->signs.clear();
world->trees.clear();
world->nuked = true;

// gather everyone here before we start moving people around
std::vector<ENetPeer*> staying;
std::vector<ENetPeer*> leaving;

peers(world_name, PEER_SAME_WORLD, [&](ENetPeer &p)
{
::peer *pOthers = static_cast<::peer*>(p.data);
if (!pOthers) return;

on::ConsoleMessage(&p, std::format("`5[```4{}`` `5has been nuked from existence!```5]``", world_name));

if (pOthers->user_id == pPeer->user_id) return; // handled last
if (pOthers->role >= MODERATOR) staying.push_back(&p);
else leaving.push_back(&p);
});

// non-staff are sent to the world menu
for (ENetPeer *p : leaving)
{
ENetEvent ev{};
ev.peer = p;
action::quit_to_exit(ev, "", false);
}

// staff reload the world so they see the cleared map
for (ENetPeer *p : staying)
{
ENetEvent ev{};
ev.peer = p;
action::quit_to_exit(ev, "", true);
action::join_request(ev, "", world_name);
}

action::quit_to_exit(event, "", true);
action::join_request(event, "", world_name);
}
2 changes: 2 additions & 0 deletions include/action/dialog_return/nuke_confirm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
extern void nuke_confirm(ENetEvent& event, const ::hPipe &hPipe);
2 changes: 2 additions & 0 deletions include/action/dialog_return/popup.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "pch.hpp"

#include "commands/playeractions.hpp"
#include "popup.hpp"

void popup(ENetEvent& event, const ::hPipe &hPipe)
{
::peer *pPeer = static_cast<::peer*>(event.peer->data);
if (wrench_action(event, hPipe)) return; // @note trade, friend, pull and the staff buttons of the wrench menu

if (hPipe["buttonClicked"] == "my_worlds")
{
Expand Down
25 changes: 3 additions & 22 deletions include/action/dialog_return/socialportal.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
#include "pch.hpp"
#include "commands/friendsys.hpp"
#include "socialportal.hpp"

void socialportal(ENetEvent& event, const ::hPipe &hPipe)
{
::peer *pPeer = static_cast<::peer*>(event.peer->data);

if (hPipe["buttonClicked"] == "showfriend")
{
send_varlist(event.peer, {
"OnDialogRequest",
"set_default_color|`o\n"
"add_label_with_icon|big|0 of 0 `wFriends Online``|left|1366|\n"
"add_spacer|small|\n"
"add_textbox|`oNone of your friends are currently online.``|left|\n"
"add_spacer|small|\n"
"add_spacer|small|\n"
"add_button|friend_all|Show offline and ignored too|noflags|0|0|\n"
"add_button|all_friends|Edit Friends|noflags|0|0|\n"
"add_button|friends_options|Friend Options|noflags|0|0|\n"
"add_button|back|Back|noflags|0|0|\n"
"add_button||Close|noflags|0|0|\n"
"end_dialog|friends|||\n"
"add_quick_exit|\n"
});
}
}
if (hPipe["buttonClicked"] == "showfriend") friends_show(event, false);
}
Loading