Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live casting system #2230

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion data/migrations/19.lua
@@ -1,3 +1,5 @@
function onUpdateDatabase()
return false
print("> Updating database to version 20 (live casting support)")
db.query("ALTER TABLE `players_online` ADD COLUMN `cast_on` tinyint(1) default '0' NOT NULL, ADD COLUMN `cast_password` varchar(40) default NULL, ADD COLUMN `cast_spectators` int(5) default '0' NOT NULL;")
return true
end
3 changes: 3 additions & 0 deletions data/migrations/20.lua
@@ -0,0 +1,3 @@
function onUpdateDatabase()
return false
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOF

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'd like you to make a pr (in my repo) fixing thus as I am not able now.

18 changes: 18 additions & 0 deletions data/talkactions/scripts/livecast.lua
@@ -0,0 +1,18 @@
function onSay(player, words, param)
local defaultParam = param

param = param:lower()
if param == '' or param == "on" then
if not player:isLiveCasting() then
player:startLiveCasting()
end
elseif param == "off" then
if player:isLiveCasting() then
player:stopLiveCasting()
end
else -- a password
if not player:isLiveCasting() then
player:startLiveCasting(defaultParam)
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOF

23 changes: 23 additions & 0 deletions data/talkactions/scripts/livecastcommands.lua
@@ -0,0 +1,23 @@
function onSay(player, words, param)
if not player:isLiveCasting() then
return true
end

if words == "!start" then
player:startLiveCasting(param)
elseif words == "!pause" then
player:pauseLiveCasting(param) -- param is reason
elseif words == "!kick" then -- where param is spectator name
player:kickCastSpectator(param)
elseif words == "!ban" then
player:banCastSpectator(param)
elseif words == "!unban" then
player:unBanCastSpectator(param)
elseif words == "!mute" then
player:muteCastSpectator(param)
elseif words == "!unmute" then
player:unMuteCastSpectator(param)
end

return false
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOF

10 changes: 10 additions & 0 deletions data/talkactions/talkactions.xml
Expand Up @@ -47,6 +47,16 @@
<talkaction words="!online" script="online.lua" />
<talkaction words="!serverinfo" script="serverinfo.lua" />

<!-- cast talkactions -->
<talkaction words="!cast" separator=" " script="livecast.lua" />
<talkaction words="!pause" channel="cast" separator=" " script="livecastcommands.lua" />
<talkaction words="!start" channel="cast" separator=" " script="livecastcommands.lua" />
<talkaction words="!kick" channel="cast" separator=" " script="livecastcommands.lua" />
<talkaction words="!ban" channel="cast" separator=" " script="livecastcommands.lua" />
<talkaction words="!unban" channel="cast" separator=" " script="livecastcommands.lua" />
<talkaction words="!mute" channel="cast" separator=" " script="livecastcommands.lua" />
<talkaction words="!unmute" channel="cast" separator=" " script="livecastcommands.lua" />

<!-- test talkactions -->
<talkaction words="!z" separator=" " script="magiceffect.lua" />
<talkaction words="!x" separator=" " script="animationeffect.lua" />
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -51,8 +51,10 @@ set(tfs_SRC
${CMAKE_CURRENT_LIST_DIR}/position.cpp
${CMAKE_CURRENT_LIST_DIR}/protocol.cpp
${CMAKE_CURRENT_LIST_DIR}/protocolgame.cpp
${CMAKE_CURRENT_LIST_DIR}/protocolgamebase.cpp
${CMAKE_CURRENT_LIST_DIR}/protocollogin.cpp
${CMAKE_CURRENT_LIST_DIR}/protocolold.cpp
${CMAKE_CURRENT_LIST_DIR}/protocolspectator.cpp
${CMAKE_CURRENT_LIST_DIR}/protocolstatus.cpp
${CMAKE_CURRENT_LIST_DIR}/quests.cpp
${CMAKE_CURRENT_LIST_DIR}/raids.cpp
Expand Down
4 changes: 3 additions & 1 deletion src/configmanager.cpp
@@ -1,4 +1,4 @@
/**
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2017 Mark Samman <mark.samman@gmail.com>
*
Expand Down Expand Up @@ -111,6 +111,7 @@ bool ConfigManager::load()

integer[SQL_PORT] = getGlobalNumber(L, "mysqlPort", 3306);
integer[GAME_PORT] = getGlobalNumber(L, "gameProtocolPort", 7172);
integer[CAST_PORT] = getGlobalNumber(L, "loveCastProtocolPort", 7173);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you in love?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you teach me how do you do comment like this ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files changes -> go to a line, put the marker next to a line number and click the blue + box :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

integer[LOGIN_PORT] = getGlobalNumber(L, "loginProtocolPort", 7171);
integer[STATUS_PORT] = getGlobalNumber(L, "statusProtocolPort", 7171);

Expand All @@ -131,6 +132,7 @@ bool ConfigManager::load()
boolean[WARN_UNSAFE_SCRIPTS] = getGlobalBoolean(L, "warnUnsafeScripts", true);
boolean[CONVERT_UNSAFE_SCRIPTS] = getGlobalBoolean(L, "convertUnsafeScripts", true);
boolean[CLASSIC_EQUIPMENT_SLOTS] = getGlobalBoolean(L, "classicEquipmentSlots", false);
boolean[LIVE_CAST_ENABLED] = getGlobalBoolean(L, "liveCastEnabled", true);

string[DEFAULT_PRIORITY] = getGlobalString(L, "defaultPriority", "high");
string[SERVER_NAME] = getGlobalString(L, "serverName", "");
Expand Down
4 changes: 3 additions & 1 deletion src/configmanager.h
@@ -1,4 +1,4 @@
/**
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2017 Mark Samman <mark.samman@gmail.com>
*
Expand Down Expand Up @@ -40,6 +40,7 @@ class ConfigManager
WARN_UNSAFE_SCRIPTS,
CONVERT_UNSAFE_SCRIPTS,
CLASSIC_EQUIPMENT_SLOTS,
LIVE_CAST_ENABLED,

LAST_BOOLEAN_CONFIG /* this must be the last one */
};
Expand Down Expand Up @@ -90,6 +91,7 @@ class ConfigManager
FRAG_TIME,
WHITE_SKULL_TIME,
GAME_PORT,
CAST_PORT,
LOGIN_PORT,
STATUS_PORT,
STAIRHOP_DELAY,
Expand Down
5 changes: 4 additions & 1 deletion src/const.h
@@ -1,4 +1,4 @@
/**
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2017 Mark Samman <mark.samman@gmail.com>
*
Expand Down Expand Up @@ -548,8 +548,11 @@ enum ReloadTypes_t : uint8_t {

static constexpr int32_t CHANNEL_GUILD = 0x00;
static constexpr int32_t CHANNEL_PARTY = 0x01;
static constexpr int32_t CHANNEL_CAST = 0xFF;
static constexpr int32_t CHANNEL_PRIVATE = 0xFFFF;

static constexpr auto CHANNEL_CAST_STR = "Live Cast";

//Reserved player storage key ranges;
//[10000000 - 20000000];
static constexpr int32_t PSTRG_RESERVED_RANGE_START = 10000000;
Expand Down
22 changes: 18 additions & 4 deletions src/game.cpp
@@ -1,4 +1,4 @@
/**
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2017 Mark Samman <mark.samman@gmail.com>
*
Expand Down Expand Up @@ -1820,6 +1820,11 @@ void Game::playerCloseChannel(uint32_t playerId, uint16_t channelId)
return;
}

if (channelId == CHANNEL_CAST) {
player->stopLiveCasting();
return;
}

g_chat->removeUserFromChannel(*player, channelId);
}

Expand Down Expand Up @@ -3036,6 +3041,10 @@ void Game::playerSetFightModes(uint32_t playerId, fightMode_t fightMode, bool ch
player->setFightMode(fightMode);
player->setChaseMode(chaseMode);
player->setSecureMode(secureMode);

if (player->isLiveCasting()) {
player->sendFightModes(); // to update the spectator
}
}

void Game::playerRequestAddVip(uint32_t playerId, const std::string& name)
Expand Down Expand Up @@ -3233,7 +3242,7 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type,
return;
}

if (playerSaySpell(player, type, text)) {
if (playerSaySpell(player, type, channelId, text)) {
return;
}

Expand All @@ -3245,6 +3254,11 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type,
player->removeMessageBuffer();
}

if (channelId == CHANNEL_CAST) {
player->sendChannelMessage(player->getName(), text, TALKTYPE_CHANNEL_O, CHANNEL_CAST);
return;
}

switch (type) {
case TALKTYPE_SAY:
internalCreatureSay(player, TALKTYPE_SAY, text, false);
Expand Down Expand Up @@ -3282,11 +3296,11 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type,
}
}

bool Game::playerSaySpell(Player* player, SpeakClasses type, const std::string& text)
bool Game::playerSaySpell(Player* player, SpeakClasses type, uint16_t channelId, const std::string& text)
{
std::string words = text;

TalkActionResult_t result = g_talkActions->playerSaySpell(player, type, words);
TalkActionResult_t result = g_talkActions->playerSaySpell(player, type, channelId, words);
if (result == TALKACTION_BREAK) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/game.h
@@ -1,4 +1,4 @@
/**
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2017 Mark Samman <mark.samman@gmail.com>
*
Expand Down Expand Up @@ -503,7 +503,7 @@ class Game
Quests quests;

protected:
bool playerSaySpell(Player* player, SpeakClasses type, const std::string& text);
bool playerSaySpell(Player* player, SpeakClasses type, uint16_t channelId, const std::string& text);
void playerWhisper(Player* player, const std::string& text);
bool playerYell(Player* player, const std::string& text);
bool playerSpeakTo(Player* player, SpeakClasses type, const std::string& receiver, const std::string& text);
Expand Down
27 changes: 24 additions & 3 deletions src/iologindata.cpp
@@ -1,4 +1,4 @@
/**
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2017 Mark Samman <mark.samman@gmail.com>
*
Expand Down Expand Up @@ -183,16 +183,37 @@ void IOLoginData::updateOnlineStatus(uint32_t guid, bool login)
if (g_config.getBoolean(ConfigManager::ALLOW_CLONES)) {
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing Space

std::ostringstream query;
if (login) {
query << "INSERT INTO `players_online` VALUES (" << guid << ')';
query << "INSERT INTO `players_online` (`player_id`, `cast_on`, `cast_password`, `cast_spectators`) VALUES (" << guid << ", 0, '', 0)";
} else {
query << "DELETE FROM `players_online` WHERE `player_id` = " << guid;
}
Database::getInstance().executeQuery(query.str());
}

void IOLoginData::startCast(uint32_t guid, std::string password)
{
Database& db = Database::getInstance();
std::ostringstream query;
query << "UPDATE `players_online` set `cast_on` = 1, `cast_password` = " << db.escapeString(password) << ", `cast_spectators` = 0 WHERE `player_id` = " << guid;
db.executeQuery(query.str());
}

void IOLoginData::updateCast(uint32_t guid, uint32_t spectators)
{
std::ostringstream query;
query << "UPDATE `players_online` set `cast_spectators = " << spectators << " WHERE `player_id` = " << guid;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query << "UPDATE players_online set cast_spectators = " << spectators << " WHERE player_id = " << guid;

You are missing "`"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can u make a pr, I can't have a pc for a while. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, if I did this correct

}

void IOLoginData::stopCast(uint32_t guid)
{
std::ostringstream query;
query << "UPDATE `players_online` set `cast_on` = 0, `cast_password` = '', `cast_spectators` = 0 WHERE `player_id` = " << guid;
Database::getInstance().executeQuery(query.str());
}

bool IOLoginData::preloadPlayer(Player* player, const std::string& name)
{
Database& db = Database::getInstance();
Expand Down
5 changes: 4 additions & 1 deletion src/iologindata.h
@@ -1,4 +1,4 @@
/**
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2017 Mark Samman <mark.samman@gmail.com>
*
Expand Down Expand Up @@ -38,6 +38,9 @@ class IOLoginData
static AccountType_t getAccountType(uint32_t accountId);
static void setAccountType(uint32_t accountId, AccountType_t accountType);
static void updateOnlineStatus(uint32_t guid, bool login);
static void startCast(uint32_t guid, std::string password);
static void updateCast(uint32_t guid, uint32_t spectators);
static void stopCast(uint32_t guid);
static bool preloadPlayer(Player* player, const std::string& name);

static bool loadPlayerById(Player* player, uint32_t id);
Expand Down