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) // 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 // create the messge that will contain the chat message
pfKIMsg *msg = new pfKIMsg( pfKIMsg::kHACKChatMsg ); 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::kNetPropagate | plMessage::kNetForce);
msg->SetBCastFlag(plMessage::kLocalPropagate, 0); msg->SetBCastFlag(plMessage::kLocalPropagate, 0);
if (tolist.size() > 0) // this goes to everybody on the shard
{ if (flags & pfKIMsg::kGlobalMsg)
#ifndef PLASMA_EXTERNAL_RELEASE msg->SetBCastFlag(plMessage::kCCRSendToAllPlayers);
// this goes to everybody on the shard // allow inter-age routing of this msg
if (flags & pfKIMsg::kGlobalMsg) if (flags & pfKIMsg::kInterAgeMsg)
msg->SetAllBCastFlags(plMessage::kCCRSendToAllPlayers); msg->SetBCastFlag( plMessage::kNetAllowInterAge );
#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);
if (tolist.size() > 0) // add net rcvrs to msg
for ( auto it = tolist.begin(); it != tolist.end(); ++it )
{ {
#ifndef PLASMA_EXTERNAL_RELEASE pyPlayer* to = *it;
// this goes to everybody on the shard if ( !VaultAmIgnoringPlayer( to->GetPlayerID() ) )
if (flags & pfKIMsg::kGlobalMsg) msg->AddNetReceiver(to->GetPlayerID());
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());
}
} }
uint32_t msgFlags = msg->GetFlags(); msg->Send();
return flags;
if (tolist.size() == 0 || (msg->GetNetReceivers() && msg->GetNetReceivers()->size() > 0))
msg->Send();
return msgFlags;
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

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

@ -462,8 +462,7 @@ public:
// //
// RETURNS : the flags that were sent with the message (may be modified) // 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(const pyPlayer& from, const std::vector<pyPlayer*> & tolist, const plString& message, uint32_t flags);
static uint32_t SendRTChat(pyPlayer& from, const std::vector<pyPlayer*> & tolist, const wchar_t* 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* fromPlayerObj = NULL;
PyObject* toPlayerListObj = NULL; PyObject* toPlayerListObj = NULL;
PyObject* message = NULL; PyObject* message = NULL;
unsigned long msgFlags; uint32_t msgFlags = 0;
if (!PyArg_ParseTuple(args, "OOOl", &fromPlayerObj, &toPlayerListObj, &message, &msgFlags)) 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; PYTHON_RETURN_ERROR;
} }
if (!pyPlayer::Check(fromPlayerObj)) 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; PYTHON_RETURN_ERROR;
} }
pyPlayer* sender = pyPlayer::ConvertFrom(fromPlayerObj);
pyPlayer* fromPlayer = pyPlayer::ConvertFrom(fromPlayerObj); if (!PySequence_Check(toPlayerListObj))
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
{ {
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; PYTHON_RETURN_ERROR;
} }
std::vector<pyPlayer*> toPlayers;
if (PyString_Check(message)) toPlayers.reserve(PySequence_Size(toPlayerListObj));
{ for (Py_ssize_t i = 0; i < PySequence_Size(toPlayerListObj); ++i)
char* msg = PyString_AsString(message);
return PyLong_FromUnsignedLong(cyMisc::SendRTChat(*fromPlayer, toPlayerList, msg, msgFlags));
}
else if (PyUnicode_Check(message))
{ {
int size = PyUnicode_GetSize(message); PyObject* item = PySequence_GetItem(toPlayerListObj, i);
wchar_t* msg = new wchar_t[size + 1]; msg[size] = 0; if (!pyPlayer::Check(item))
PyUnicode_AsWideChar((PyUnicodeObject*)message, msg, size); {
uint32_t retval = cyMisc::SendRTChat(*fromPlayer, toPlayerList, msg, msgFlags); PyErr_SetString(PyExc_TypeError, err);
delete msg; PYTHON_RETURN_ERROR;
return PyLong_FromUnsignedLong(retval); }
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; 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" PYTHON_GLOBAL_METHOD_DEFINITION(PtSendKIMessage, args, "Params: command,value\nSends a command message to the KI frontend.\n"

Loading…
Cancel
Save