Skip to content

Commit

Permalink
Live casting system #2230
Browse files Browse the repository at this point in the history
slavidodo:casting-system

and Remove Shaders, Auras, Wings, Fix ProtocolGameBase according OTCv8 Features

Co-Authored-By: slavi <[email protected]>
  • Loading branch information
Corlyone and slavidodo committed Nov 6, 2021
1 parent f79e0b5 commit 411cd19
Show file tree
Hide file tree
Showing 32 changed files with 3,845 additions and 2,085 deletions.
4 changes: 3 additions & 1 deletion data/migrations/25.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
function onUpdateDatabase()
return false
print("> Updating database to version 25 (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/26.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function onUpdateDatabase()
return false
end
18 changes: 18 additions & 0 deletions data/talkactions/scripts/livecast.lua
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions data/talkactions/scripts/livecastcommands.lua
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions data/talkactions/talkactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ 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
2 changes: 2 additions & 0 deletions src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ bool ConfigManager::load()

integer[SQL_PORT] = getGlobalNumber(L, "mysqlPort", 3306);
integer[GAME_PORT] = getGlobalNumber(L, "gameProtocolPort", 7172);
integer[CAST_PORT] = getGlobalNumber(L, "liveCastProtocolPort", 7173);
integer[LOGIN_PORT] = getGlobalNumber(L, "loginProtocolPort", 7171);
integer[STATUS_PORT] = getGlobalNumber(L, "statusProtocolPort", 7171);

Expand Down Expand Up @@ -175,6 +176,7 @@ bool ConfigManager::load()
boolean[CLEAN_PROTECTION_ZONES] = getGlobalBoolean(L, "cleanProtectionZones", false);
boolean[HOUSE_DOOR_SHOW_PRICE] = getGlobalBoolean(L, "houseDoorShowPrice", true);
boolean[PACKET_COMPRESSION] = getGlobalBoolean(L, "packetCompression", true);
boolean[LIVE_CAST_ENABLED] = getGlobalBoolean(L, "liveCastEnabled", true);

string[DEFAULT_PRIORITY] = getGlobalString(L, "defaultPriority", "high");
string[SERVER_NAME] = getGlobalString(L, "serverName", "");
Expand Down
2 changes: 2 additions & 0 deletions src/configmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ConfigManager
WARN_UNSAFE_SCRIPTS,
CONVERT_UNSAFE_SCRIPTS,
CLASSIC_EQUIPMENT_SLOTS,
LIVE_CAST_ENABLED,
CLASSIC_ATTACK_SPEED,
SCRIPTS_CONSOLE_LOGS,
SERVER_SAVE_NOTIFY_MESSAGE,
Expand Down Expand Up @@ -105,6 +106,7 @@ class ConfigManager
WHITE_SKULL_TIME,
IP,
GAME_PORT,
CAST_PORT,
LOGIN_PORT,
STATUS_PORT,
STAIRHOP_DELAY,
Expand Down
3 changes: 3 additions & 0 deletions src/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,11 @@ enum GameFeature : 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
20 changes: 17 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,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 @@ -2943,6 +2948,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 @@ -3082,7 +3091,7 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type,

player->resetIdleTime();

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

Expand All @@ -3102,6 +3111,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 @@ -3136,11 +3150,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, words);
if (result == TALKACTION_BREAK) {
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "npc.h"
#include "wildcardtree.h"
#include "quests.h"
#include "shaders.h"

class ServiceManager;
class Creature;
Expand Down Expand Up @@ -514,7 +513,7 @@ class Game
}

private:
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
25 changes: 24 additions & 1 deletion src/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,36 @@ void IOLoginData::updateOnlineStatus(uint32_t guid, bool login)

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)
{
Database& db = Database::getInstance();
std::ostringstream query;
query << "UPDATE `players_online` set `cast_spectators` = " << spectators << " WHERE `player_id` = " << guid;
db.executeQuery(query.str());
}

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
3 changes: 3 additions & 0 deletions src/iologindata.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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
1 change: 1 addition & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ class ItemAttributes
break;
}


case 3: { // double
double tmp;
if (!propStream.read<double>(tmp)) {
Expand Down
Loading

0 comments on commit 411cd19

Please sign in to comment.