• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved close channel network message

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,452
Solutions
1
Reaction score
625
Location
Estonia
Can i use network message to close a channel 10?
I tried something but client keeps crashing
working solution:
Code:
local msg = NetworkMessage()
msg:addByte(0xB3)
    msg:addU16(0x0A) -- channelID in ASCII
    msg:sendToPlayer(player)
    msg:delete()
Code:
void ProtocolGame::parseCloseChannel(NetworkMessage& msg)
{
   uint16_t channelId = msg.get<uint16_t>();
   addGameTask(&Game::playerCloseChannel, player->getID(), channelId);
 
Last edited:
Solution
I still recommend you to modify the source code because you still need to remove the user from the channel itself.
Code:
function Player.sendCloseChannel(self, channelId)
    local networkMessage = NetworkMessage()
    networkMessage:addByte(0xB3)
    networkMessage:addU16(channelId)
    networkMessage:sendToPlayer(self)
    networkMessage:delete()
    return true
end
edit

in protocolgame i think it only parses the channel when the function in game.cpp Game::playerOpenChannel is executed

you could source edit a new function to close channel, it would be pretty much the same function as player:eek:penChannel(channelId)
Code:
int LuaScriptInterface::luaPlayerCloseChannel(lua_State* L)
{
    // player:closeChannel(channelId)
    uint16_t channelId = getNumber<uint16_t>(L, 2);
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        g_game.playerCloseChannel(player->getId(), channelId);
        pushBoolean(L, true);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
 
Last edited:
I don't have that luascript.

I already found how source is doing it. I even showed it on opening post.
I don't know how to make it happen with Lua function using network message (if its even possible)
 
I dont have that luascript
thats what im saying, you can add it easily
it's the same luascript function but uses Game::playerCloseChannel instead of Game::playerOpenChannel in game.cpp
just register it in luascript.cpp with registerMethod and in luascript.h
 
thats what im saying, you can add it easily
it's the same luascript function but uses Game::playerCloseChannel instead of Game::playerOpenChannel in game.cpp
just register it in luascript.cpp with registerMethod and in luascript.h
I cant do that.
 
thats what im saying, you can add it easily
it's the same luascript function but uses Game::playerCloseChannel instead of Game::playerOpenChannel in game.cpp
just register it in luascript.cpp with registerMethod and in luascript.h
you can also do a pr
 
i guess try this then since you cant source edit for whatever reason
Code:
local msg = NetworkMessage()
msg:addByte(0x99) -- Byte for protocolgame::parseCloseChannel
msg:addU16(xxxxx) -- Channel id
msg:addU32(player:getId())
msg:sendToPlayer(player)
msg:delete()
 
Code:
case 0x99: parseCloseChannel(msg); break;
found this case. I assume this is the byte i need to add?

Even still, it will crash xD
 
i guess try this then since you cant source edit for whatever reason
Code:
local msg = NetworkMessage()
msg:addByte(0x98) -- Byte for protocolgame::parseCloseChannel
msg:addU16(xxxxx) -- Channel id
msg:addU32(player:getId())
msg:sendToPlayer(player)
msg:delete()
doesn't work
You can also see in source it does not require playerID..
 
I still recommend you to modify the source code because you still need to remove the user from the channel itself.
Code:
function Player.sendCloseChannel(self, channelId)
    local networkMessage = NetworkMessage()
    networkMessage:addByte(0xB3)
    networkMessage:addU16(channelId)
    networkMessage:sendToPlayer(self)
    networkMessage:delete()
    return true
end
 
Solution
edit

in protocolgame i think it only parses the channel when the function in game.cpp Game::playerOpenChannel is executed

you could source edit a new function to close channel, it would be pretty much the same function as player:eek:penChannel(channelId)
Code:
int LuaScriptInterface::luaPlayerCloseChannel(lua_State* L)
{
    // player:closeChannel(channelId)
    uint16_t channelId = getNumber<uint16_t>(L, 2);
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        g_game.playerCloseChannel(player->getId(), channelId);
        pushBoolean(L, true);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
it didn't gave me any errors while compiling but i got this error in console
Code:
Lua Script Error: [Chat Interface]
data/chatchannels/scripts/antibot.lua:onSpeak
data/chatchannels/scripts/antibot.lua:41: attempt to call method 'closeChannel' (a nil value)

This is the line in my script
Code:
        player:closeChannel(ANTI_BOT_SYSTEM.config.channelId)
 
Back
Top