Browse Source

Cleanup and plString-ify PtSendRTChat

Adam Johnson 12 years ago
parent
commit
b53d5c7989
  1. 72
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  2. 3
      Sources/Plasma/FeatureLib/pfPython/cyMisc.h
  3. 63
      Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp

72
Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

@ -1110,7 +1110,7 @@ float cyMisc::GetMaxListenDistSq()
//
// RETURNS : the flags that were sent with the message (may be modified)
//
uint32_t cyMisc::SendRTChat(pyPlayer& from, const std::vector<pyPlayer*> & tolist, const char* message, uint32_t flags)
uint32_t cyMisc::SendRTChat(const pyPlayer& from, const std::vector<pyPlayer*> & tolist, const plString& message, uint32_t flags)
{
// create the messge that will contain the chat message
pfKIMsg *msg = new pfKIMsg( pfKIMsg::kHACKChatMsg );
@ -1120,67 +1120,23 @@ uint32_t cyMisc::SendRTChat(pyPlayer& from, const std::vector<pyPlayer*> & tolis
msg->SetBCastFlag(plMessage::kNetPropagate | plMessage::kNetForce);
msg->SetBCastFlag(plMessage::kLocalPropagate, 0);
if (tolist.size() > 0)
{
#ifndef PLASMA_EXTERNAL_RELEASE
// this goes to everybody on the shard
if (flags & pfKIMsg::kGlobalMsg)
msg->SetAllBCastFlags(plMessage::kCCRSendToAllPlayers);
#endif
// allow inter-age routing of this msg
if (flags & pfKIMsg::kInterAgeMsg)
msg->SetBCastFlag( plMessage::kNetAllowInterAge );
// add net rcvrs to msg
int i;
for ( i=0 ; i<tolist.size() ; i++ )
{
if ( !VaultAmIgnoringPlayer( tolist[i]->GetPlayerID() ) )
msg->AddNetReceiver(tolist[i]->GetPlayerID());
}
}
uint32_t msgFlags = msg->GetFlags();
if (tolist.size() == 0 || (msg->GetNetReceivers() && msg->GetNetReceivers()->size() > 0))
msg->Send();
return msgFlags;
}
uint32_t cyMisc::SendRTChat(pyPlayer& from, const std::vector<pyPlayer*> & tolist, const wchar_t* message, uint32_t flags)
{
// create the messge that will contain the chat message
pfKIMsg *msg = new pfKIMsg( pfKIMsg::kHACKChatMsg );
msg->SetString( plString::FromWchar(message) );
msg->SetUser( from.GetPlayerName(), from.GetPlayerID() );
msg->SetFlags( flags );
msg->SetBCastFlag(plMessage::kNetPropagate | plMessage::kNetForce);
msg->SetBCastFlag(plMessage::kLocalPropagate, 0);
// this goes to everybody on the shard
if (flags & pfKIMsg::kGlobalMsg)
msg->SetBCastFlag(plMessage::kCCRSendToAllPlayers);
// allow inter-age routing of this msg
if (flags & pfKIMsg::kInterAgeMsg)
msg->SetBCastFlag( plMessage::kNetAllowInterAge );
if (tolist.size() > 0)
// add net rcvrs to msg
for ( auto it = tolist.begin(); it != tolist.end(); ++it )
{
#ifndef PLASMA_EXTERNAL_RELEASE
// this goes to everybody on the shard
if (flags & pfKIMsg::kGlobalMsg)
msg->SetAllBCastFlags(plMessage::kCCRSendToAllPlayers);
#endif
// allow inter-age routing of this msg
if (flags & pfKIMsg::kInterAgeMsg)
msg->SetBCastFlag( plMessage::kNetAllowInterAge );
// add net rcvrs to msg
for ( int i = 0 ; i < tolist.size() ; i++ )
{
if ( !VaultAmIgnoringPlayer( tolist[i]->GetPlayerID() ) )
msg->AddNetReceiver(tolist[i]->GetPlayerID());
}
pyPlayer* to = *it;
if ( !VaultAmIgnoringPlayer( to->GetPlayerID() ) )
msg->AddNetReceiver(to->GetPlayerID());
}
uint32_t msgFlags = msg->GetFlags();
if (tolist.size() == 0 || (msg->GetNetReceivers() && msg->GetNetReceivers()->size() > 0))
msg->Send();
return msgFlags;
msg->Send();
return flags;
}
/////////////////////////////////////////////////////////////////////////////

3
Sources/Plasma/FeatureLib/pfPython/cyMisc.h

@ -462,8 +462,7 @@ public:
//
// RETURNS : the flags that were sent with the message (may be modified)
//
static uint32_t SendRTChat(pyPlayer& from, const std::vector<pyPlayer*> & tolist, const char* message, uint32_t flags);
static uint32_t SendRTChat(pyPlayer& from, const std::vector<pyPlayer*> & tolist, const wchar_t* message, uint32_t flags);
static uint32_t SendRTChat(const pyPlayer& from, const std::vector<pyPlayer*> & tolist, const plString& message, uint32_t flags);
/////////////////////////////////////////////////////////////////////////////
//

63
Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp

@ -233,60 +233,47 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtSendRTChat, args, "Params: fromPlayer,toPlayer
PyObject* fromPlayerObj = NULL;
PyObject* toPlayerListObj = NULL;
PyObject* message = NULL;
unsigned long msgFlags;
if (!PyArg_ParseTuple(args, "OOOl", &fromPlayerObj, &toPlayerListObj, &message, &msgFlags))
uint32_t msgFlags = 0;
const char* err = "PtSendRTChat expects a ptPlayer, a sequence of ptPlayers, a string, and an optional long";
if (!PyArg_ParseTuple(args, "OOO|l", &fromPlayerObj, &toPlayerListObj, &message, &msgFlags))
{
PyErr_SetString(PyExc_TypeError, "PtSendRTChat expects a ptPlayer, a list of ptPlayers, a string, and a long");
PyErr_SetString(PyExc_TypeError, err);
PYTHON_RETURN_ERROR;
}
if (!pyPlayer::Check(fromPlayerObj))
{
PyErr_SetString(PyExc_TypeError, "PtSendRTChat expects a ptPlayer, a list of ptPlayers, a string, and a long");
PyErr_SetString(PyExc_TypeError, err);
PYTHON_RETURN_ERROR;
}
pyPlayer* sender = pyPlayer::ConvertFrom(fromPlayerObj);
pyPlayer* fromPlayer = pyPlayer::ConvertFrom(fromPlayerObj);
std::vector<pyPlayer*> toPlayerList;
if (PyList_Check(toPlayerListObj))
{
int listSize = PyList_Size(toPlayerListObj);
for (int i = 0; i < listSize; i++)
{
PyObject* listItem = PyList_GetItem(toPlayerListObj, i);
if (!pyPlayer::Check(listItem))
{
PyErr_SetString(PyExc_TypeError, "PtSendRTChat expects a ptPlayer, a list of ptPlayers, a string, and a long");
PYTHON_RETURN_ERROR;
}
toPlayerList.push_back(pyPlayer::ConvertFrom(listItem));
}
}
else
if (!PySequence_Check(toPlayerListObj))
{
PyErr_SetString(PyExc_TypeError, "PtSendRTChat expects a ptPlayer, a list of ptPlayers, a string, and a long");
PyErr_SetString(PyExc_TypeError, err);
PYTHON_RETURN_ERROR;
}
if (PyString_Check(message))
{
char* msg = PyString_AsString(message);
return PyLong_FromUnsignedLong(cyMisc::SendRTChat(*fromPlayer, toPlayerList, msg, msgFlags));
}
else if (PyUnicode_Check(message))
std::vector<pyPlayer*> toPlayers;
toPlayers.reserve(PySequence_Size(toPlayerListObj));
for (Py_ssize_t i = 0; i < PySequence_Size(toPlayerListObj); ++i)
{
int size = PyUnicode_GetSize(message);
wchar_t* msg = new wchar_t[size + 1]; msg[size] = 0;
PyUnicode_AsWideChar((PyUnicodeObject*)message, msg, size);
uint32_t retval = cyMisc::SendRTChat(*fromPlayer, toPlayerList, msg, msgFlags);
delete msg;
return PyLong_FromUnsignedLong(retval);
PyObject* item = PySequence_GetItem(toPlayerListObj, i);
if (!pyPlayer::Check(item))
{
PyErr_SetString(PyExc_TypeError, err);
PYTHON_RETURN_ERROR;
}
toPlayers.push_back(pyPlayer::ConvertFrom(item));
}
else
if (!PyString_CheckEx(message))
{
PyErr_SetString(PyExc_TypeError, "PtSendRTChat expects a ptPlayer, a list of ptPlayers, a string, and a long");
PyErr_SetString(PyExc_TypeError, err);
PYTHON_RETURN_ERROR;
}
plString chatmsg = PyString_AsStringEx(message);
return PyLong_FromUnsignedLong(cyMisc::SendRTChat(*sender, toPlayers, chatmsg, msgFlags));
}
PYTHON_GLOBAL_METHOD_DEFINITION(PtSendKIMessage, args, "Params: command,value\nSends a command message to the KI frontend.\n"

Loading…
Cancel
Save