* fixed channels & linked them with DefScript

* functions: joinchannel, leavechannel
* added script: chan.def (say on channels)
* fixed DefScript loaddef & reloaddef
* misc stuff
This commit is contained in:
False.Genesis 2007-01-21 22:02:16 +00:00
parent 9823b60377
commit 9d0dd30a0c
15 changed files with 236 additions and 187 deletions

View File

@ -21,6 +21,12 @@ SAY [${@version_short}] login successful.
// 126 = TEXTEMOTE_READY
EMOTE 126
// join some channels...
JOINCHANNEL generalchat
JOINCHANNEL help
JOINCHANNEL tradee
// ...
// add your own stuff here
// ...

12
bin/scripts/chan.def Normal file
View File

@ -0,0 +1,12 @@
// Script to write on channels
// Arguments:
// ==========
// @def: text to write
// @0: channel name
// @1: language name/number
#permission=10
SET,lang ${@1}
DEFAULT,lang 0
SENDCHATMESSAGE,14,{${lang}},{${@def}},{${@0}}

View File

@ -1,147 +0,0 @@
#include "common.h"
#include "PseuWoW.h"
#include "Channel.h"
void Channel::Join(std::string channel, std::string password)
{
if (IsOnChannel(channel))
return;
// Send join channel request
WorldPacket worldPacket;
worldPacket.SetOpcode(CMSG_JOIN_CHANNEL);
worldPacket << channel << password;
_worldSession->SendWorldPacket(worldPacket);
// Put in channels-joined list, but don't flag as joined yet
ChannelStruct channelStruct;
channelStruct.channel = "TestChannel";
channelStruct.password = "";
channelStruct.joined = false;
channels.push_back(channelStruct);
}
void Channel::Leave(std::string channel)
{
for(std::vector<ChannelStruct>::iterator i = channels.begin(); i != channels.end(); i++)
{
ChannelStruct s = *(i);
if (s.channel == channel)
{
if (s.joined)
{
// Send leave channel request
WorldPacket worldPacket;
worldPacket.SetOpcode(CMSG_LEAVE_CHANNEL);
worldPacket << channel;
_worldSession->SendWorldPacket(worldPacket);
}
}
}
}
void Channel::Say(std::string channel, std::string text, uint32 lang)
{
_worldSession->SendChatMessage(CHAT_MSG_CHANNEL, lang, text, channel);
}
bool Channel::IsOnChannel(std::string channel)
{
for(std::vector<ChannelStruct>::iterator i = channels.begin(); i != channels.end(); i++)
{
ChannelStruct s = *(i);
if (s.channel == channel)
{
if (s.joined)
{
return true;
}
}
}
return false;
}
void Channel::HandleNotifyOpcode(WorldPacket &packet)
{
uint8 code;
uint64 guid;
std::string channel, name;
packet >> code >> channel;
for(std::vector<ChannelStruct>::iterator i = channels.begin(); i != channels.end(); i++)
{
ChannelStruct s = *(i);
if (s.channel == channel)
{
switch (code)
{
// Player joined channel you are on
case 0x00:
packet >> guid;
if(guid){
name = _worldSession->plrNameCache.GetName(guid);
if (name.empty())
{
_worldSession->SendQueryPlayerName(guid);
name = "Unknown Entity";
}
}
printf("%s joined channel %s\n", channel.c_str());
break;
// Player leaved channel you are on
case 0x01:
packet >> guid;
if(guid){
name = _worldSession->plrNameCache.GetName(guid);
if (name.empty())
{
_worldSession->SendQueryPlayerName(guid);
name = "Unknown Entity";
}
}
printf("%s leaved channel %s\n", channel.c_str());
break;
// You joined channel successfully
case 0x02:
s.joined = true;
printf("You joined channel %s\n", channel.c_str());
break;
// You leaved channel successfully
case 0x03:
channels.erase(i);
printf("You leaved channel %s\n", channel.c_str());
break;
// Wrong password while trying to join channel
case 0x04:
channels.erase(i);
printf("Could not join channel %s (Wrong password)\n", channel.c_str());
break;
// Not on channel while trying to write to channel etc.
case 0x05:
channels.erase(i);
printf("Your are not on channel %s\n", channel.c_str());
break;
}
return;
}
}
// TODO: Even more channel notices to handle
/*
printf("Channel notice not handled! Code: %d - Channel name: %s\nData:\n", code, channel.c_str());
packet.textlike();
printf("\n");
*/
}

View File

@ -65,6 +65,8 @@ DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const
//{"follow",&DefScriptPackage::SCfollow},
{"savecache",&DefScriptPackage::SCsavecache},
{"sendchatmessage",&DefScriptPackage::SCSendChatMessage},
{"joinchannel",&DefScriptPackage::SCjoinchannel},
{"leavechannel",&DefScriptPackage::SCleavechannel},
// table termination
{NULL,NULL}

View File

@ -145,6 +145,8 @@ private:
bool SCemote(CmdSet);
bool SCfollow(CmdSet);
bool SCshdn(CmdSet);
bool SCjoinchannel(CmdSet);
bool SCleavechannel(CmdSet);
// Own variable declarations
std::map<std::string, unsigned char> my_usrPermissionMap;

View File

@ -32,7 +32,10 @@ bool DefScriptPackage::func_loaddef(CmdSet Set){
bool result=false;
std::string fn;
if(Set.arg[0].empty())
{
result=LoadByName(Set.defaultarg);
fn=(scPath + Set.defaultarg).append(".def");
}
else
{
std::string::size_type pos = Set.arg[0].find('/');
@ -42,16 +45,19 @@ bool DefScriptPackage::func_loaddef(CmdSet Set){
fn=Set.arg[0];
result=LoadScriptFromFile(fn,Set.defaultarg);
}
//if(!result && curIsDebug)
// std::cout << "Could not load script '" << Set->defaultarg << "' [" << fn << "]\n";
return result;
if(!result)
std::cout << "Could not load script '" << Set.defaultarg << "' [" << fn << "]\n";
return true;
}
bool DefScriptPackage::func_reloaddef(CmdSet Set){
bool result=false;
std::string fn;
if(Set.arg[0].empty())
{
result=LoadByName(Set.defaultarg);
fn=(scPath + Set.defaultarg).append(".def");
}
else
{
std::string::size_type pos = Set.arg[0].find('/');
@ -61,9 +67,9 @@ bool DefScriptPackage::func_reloaddef(CmdSet Set){
fn=Set.arg[0];
result=LoadScriptFromFile(fn,Set.defaultarg);
}
//if(!result && curIsDebug)
// std::cout << "Could not load script '" << Set->defaultarg << "' [" << fn << "]\n";
return result;
if(!result)
std::cout << "Could not load script '" << Set.defaultarg << "' [" << fn << "]\n";
return true;
}
bool DefScriptPackage::func_unset(CmdSet Set){

View File

@ -7,6 +7,7 @@
#include "Opcodes.h"
#include "SharedDefines.h"
#include "WorldSession.h"
#include "Channel.h"
bool DefScriptPackage::SCshdn(CmdSet Set)
{
@ -70,8 +71,6 @@ bool DefScriptPackage::SCemote(CmdSet Set){
uint32 id=atoi(Set.defaultarg.c_str());
((PseuInstance*)parentMethod)->GetWSession()->SendEmote(id);
return true;
}
bool DefScriptPackage::SCfollow(CmdSet Set){
@ -92,6 +91,30 @@ bool DefScriptPackage::SCfollow(CmdSet Set){
}
bool DefScriptPackage::SCjoinchannel(CmdSet Set){
if(Set.defaultarg.empty())
return true;
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
{
log("Invalid Script call: SCjoinchannel: WorldSession not valid");
return false;
}
((PseuInstance*)parentMethod)->GetWSession()->GetChannels()->Join(Set.defaultarg,Set.arg[0]);
return true;
}
bool DefScriptPackage::SCleavechannel(CmdSet Set){
if(Set.defaultarg.empty())
return true;
if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid()))
{
log("Invalid Script call: SCleavechannel: WorldSession not valid");
return false;
}
((PseuInstance*)parentMethod)->GetWSession()->GetChannels()->Leave(Set.defaultarg);
return true;
}
void DefScriptPackage::My_LoadUserPermissions(VarSet &vs)
{

View File

@ -4,6 +4,7 @@
#include "Opcodes.h"
#include "Player.h"
#include "WorldSession.h"
#include "Channel.h"
void WorldSession::SendChatMessage(uint32 type, uint32 lang, std::string msg, std::string to){
if((!_valid) || (!_logged) || msg.empty())
@ -24,7 +25,7 @@ void WorldSession::SendChatMessage(uint32 type, uint32 lang, std::string msg, st
packet<<to<<msg;
break;
case CHAT_MSG_CHANNEL:
if(to.empty() || !_channel->IsOnChannel(to))
if(to.empty() /*|| !_channels->IsOnChannel(to)*/)
return;
packet<<to<<msg;
break;

View File

@ -0,0 +1,129 @@
#include "common.h"
#include "PseuWoW.h"
#include <map>
#include "Channel.h"
void Channel::Join(std::string channel, std::string password)
{
if (IsOnChannel(channel))
return;
// Send join channel request
WorldPacket worldPacket;
worldPacket.SetOpcode(CMSG_JOIN_CHANNEL);
worldPacket << channel << password;
_worldSession->SendWorldPacket(worldPacket);
}
void Channel::Leave(std::string channel)
{
for(std::vector<std::string>::iterator i = channels.begin(); i != channels.end(); i++)
{
if (*i == channel)
{
// Send leave channel request
WorldPacket worldPacket;
worldPacket.SetOpcode(CMSG_LEAVE_CHANNEL);
worldPacket << channel;
_worldSession->SendWorldPacket(worldPacket);
return;
}
}
log("Can't leave channel \"%s\": not joined",channel.c_str());
}
void Channel::Say(std::string channel, std::string text, uint32 lang)
{
_worldSession->SendChatMessage(CHAT_MSG_CHANNEL, lang, text, channel);
}
bool Channel::IsOnChannel(std::string channel)
{
for(std::vector<std::string>::iterator i = channels.begin(); i != channels.end(); i++)
{
if (*i == channel)
{
return true;
}
}
return false;
}
void Channel::HandleNotifyOpcode(WorldPacket &packet)
{
uint8 code;
uint64 guid;
std::string channel, name;
packet >> code >> channel;
switch (code)
{
// Player joined channel you are on
case 0x00:
packet >> guid;
if(guid){
name = _worldSession->plrNameCache.GetName(guid);
if (name.empty())
{
_worldSession->SendQueryPlayerName(guid);
name = "Unknown Entity";
}
}
logdetail("%s joined channel %s", channel.c_str());
break;
// Player leaved channel you are on
case 0x01:
packet >> guid;
if(guid){
name = _worldSession->plrNameCache.GetName(guid);
if (name.empty())
{
_worldSession->SendQueryPlayerName(guid);
name = "Unknown Entity";
}
}
logdetail("%s leaved channel %s", channel.c_str());
break;
// You joined channel successfully
case 0x02:
log("Joined channel %s", channel.c_str());
channels.push_back(channel);
break;
// You leaved channel successfully
case 0x03:
for(std::vector<std::string>::iterator i = channels.begin(); i != channels.end(); i++)
{
if(*i == channel)
{
channels.erase(i);
break;
}
}
log("Left channel %s", channel.c_str());
break;
// Wrong password while trying to join channel
case 0x04:
log("Could not join channel %s (Wrong password)", channel.c_str());
break;
// Not on channel while trying to write to channel etc.
case 0x05:
log("You are not on channel %s", channel.c_str());
break;
}
// TODO: Even more channel notices to handle
/*
printf("Channel notice not handled! Code: %d - Channel name: %s\nData:\n", code, channel.c_str());
packet.textlike();
printf("\n");
*/
}

View File

@ -6,13 +6,6 @@
#include "WorldPacket.h"
#include "WorldSession.h"
struct ChannelStruct
{
std::string channel;
std::string password;
bool joined;
};
class Channel
{
public:
@ -30,7 +23,7 @@ public:
// TODO: Add Kick/Ban/Mode/Owner/Mute/Invite and all that stuff
private:
std::vector<ChannelStruct>channels;
std::vector<std::string> channels;
WorldSession *_worldSession;
};

View File

@ -8,7 +8,8 @@
#include "WorldSocket.h"
#include "NameTables.h"
#include "RealmSocket.h"
#include "../Chat.h"
#include "Chat.h"
#include "Channel.h"
#include "WorldSession.h"
@ -23,6 +24,7 @@ WorldSession::WorldSession(PseuInstance *in)
_myGUID=0; // i dont have a guid yet
plrNameCache.ReadFromFile(); // load names/guids of known players
_deleteme = false;
_channels = new Channel(this);
//...
}
@ -37,6 +39,7 @@ WorldSession::~WorldSession()
}
_OnLeaveWorld();
delete _channels;
//delete _socket; the socket will be deleted by its handler!!
}
@ -136,6 +139,7 @@ OpcodeHandler *WorldSession::_GetOpcodeHandlerTable() const
{SMSG_PONG, &WorldSession::_HandlePongOpcode},
{SMSG_TRADE_STATUS, &WorldSession::_HandleTradeStatusOpcode},
{SMSG_GROUP_INVITE, &WorldSession::_HandleGroupInviteOpcode},
{SMSG_CHANNEL_NOTIFY, &WorldSession::_HandleChannelNotifyOpcode},
// movement opcodes
{MSG_MOVE_SET_FACING, &WorldSession::_HandleMovementOpcode},
@ -353,14 +357,17 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket)
uint8 type=0;
uint32 lang=0;
uint64 target_guid=0;
uint32 msglen=0;
std::string msg,ext;
uint32 msglen=0,unk;
std::string msg,channel="";
bool isCmd=false;
recvPacket >> type >> lang;
if (type == CHAT_MSG_CHANNEL)
recvPacket >> ext; // extract channel name
{
recvPacket >> channel; // extract channel name
recvPacket >> unk;
}
recvPacket >> target_guid;
std::string plrname;
@ -380,12 +387,21 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket)
recvPacket >> target_guid;
recvPacket >> msglen >> msg;
if (type == CHAT_MSG_SYSTEM){
if (type == CHAT_MSG_SYSTEM)
{
log("SYSMSG: \"%s\"",msg.c_str());
} else if (type==CHAT_MSG_WHISPER ){
log("W:WHISP: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str());
} else {
log("W:CHAT: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str());
}
else if (type==CHAT_MSG_WHISPER )
{
log("WHISP: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str());
}
else if (type==CHAT_MSG_CHANNEL )
{
log("CHANNEL [%s]: %s [%s]: %s",channel.c_str(),plrname.c_str(),LookupName(lang,langNames),msg.c_str());
}
else
{
log("CHAT: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str());
}
if(target_guid!=_myGUID && msg.length()>1 && msg.at(0)=='-' && GetInstance()->GetConf()->allowgamecmd)
@ -527,4 +543,9 @@ void WorldSession::_HandleTelePortAckOpcode(WorldPacket& recvPacket)
response.SetOpcode(MSG_MOVE_FALL_LAND);
response << uint32(0) << uint32(0) << x << y << z << o << uint32(0);
SendWorldPacket(response);
}
void WorldSession::_HandleChannelNotifyOpcode(WorldPacket& recvPacket)
{
_channels->HandleNotifyOpcode(recvPacket);
}

View File

@ -11,7 +11,7 @@
class WorldSocket;
class WorldPacket;
class PingerThread;
class Channel;
struct OpcodeHandler
{
@ -46,6 +46,7 @@ public:
void SetFollowTarget(uint64 guid);
uint64 GetFollowTarget(void) { return _followGUID; }
uint64 GetGuid(void) { return _myGUID; }
Channel *GetChannels(void) { return _channels; }
// CMSGConstructor
@ -75,8 +76,9 @@ private:
void _HandlePongOpcode(WorldPacket& recvPacket);
void _HandleTradeStatusOpcode(WorldPacket& recvPacket);
void _HandleGroupInviteOpcode(WorldPacket& recvPacket);
void _HandleTelePortAckOpcode(WorldPacket& recvPacket);
void _HandleChannelNotifyOpcode(WorldPacket& recvPacket);
PlayerEnum _player; // The connected character
@ -85,6 +87,7 @@ private:
ZThread::LockedQueue<WorldPacket*,ZThread::FastMutex> pktQueue;
bool _valid,_authed,_logged,_deleteme; // world status
SocketHandler _sh; // handles the WorldSocket
Channel *_channels;
uint64 _targetGUID,_followGUID,_myGUID;
};

View File

@ -263,6 +263,12 @@
<Filter
Name="World"
Filter="">
<File
RelativePath=".\Client\World\Channel.cpp">
</File>
<File
RelativePath=".\Client\World\Channel.h">
</File>
<File
RelativePath=".\Client\World\CMSGConstructor.cpp">
</File>

View File

@ -38,11 +38,10 @@
#endif
#if COMPILER == COMPILER_MICROSOFT
# pragma warning( disable : 4267 ) // conversion from 'size_t' to 'int', possible loss of data
# pragma warning( disable : 4786 ) // identifier was truncated to '255' characters in the debug information
#ifndef _DEBUG
# pragma warning( disable : 4244 ) // conversion from 'uint64' to 'int16', possible loss of data
#endif
# pragma warning( disable : 4267 ) // conversion from 'size_t' to 'int', possible loss of data
# pragma warning( disable : 4786 ) // identifier was truncated to '255' characters in the debug information
# pragma warning( disable : 4800 ) // conversion to bool, performance warning
# pragma warning( disable : 4244 ) // conversion from 'uint64' to 'int16', possible loss of data
#endif
////////////////////////////////////

View File

@ -2,10 +2,3 @@ realm login:
- use the correct IP in CLIENT_LOGON_CHALLENGE, and not 127.0.0.1
- use correct timezone, maybe settable via conf file later on
- define the crc_hash as it should be
controller:
- complete recoding
shared:
-fix CircularBuffer::IncreaseSize() (its BUGGED and corrupts the data)