Browse Source

Merge pull request #44 from Hoikas/rt_unicode

PtSendRTChat unicode support
Adam Johnson 14 years ago
parent
commit
3aa556bdf9
  1. 33
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  2. 1
      Sources/Plasma/FeatureLib/pfPython/cyMisc.h
  3. 24
      Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp

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

@ -1097,6 +1097,39 @@ UInt32 cyMisc::SendRTChat(pyPlayer& from, const std::vector<pyPlayer*> & tolist,
return msgFlags;
}
UInt32 cyMisc::SendRTChat(pyPlayer& from, const std::vector<pyPlayer*> & tolist, const wchar_t* message, UInt32 flags)
{
// create the messge that will contain the chat message
pfKIMsg *msg = TRACKED_NEW pfKIMsg( pfKIMsg::kHACKChatMsg );
msg->SetString( 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)
{
if (flags & 8/* kRTChatInterAge in PlasmaKITypes.py */)
{
// allow inter-age routing of this msg
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 msgFlags = msg->GetFlags();
if (tolist.size() == 0 || (msg->GetNetReceivers() && msg->GetNetReceivers()->size() > 0))
msg->Send();
return msgFlags;
}
/////////////////////////////////////////////////////////////////////////////
//
// Function : SendKIMessage

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

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

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

@ -196,9 +196,9 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtSendRTChat, args, "Params: fromPlayer,toPlayer
{
PyObject* fromPlayerObj = NULL;
PyObject* toPlayerListObj = NULL;
char* message = NULL;
PyObject* message = NULL;
unsigned long msgFlags;
if (!PyArg_ParseTuple(args, "OOsl", &fromPlayerObj, &toPlayerListObj, &message, &msgFlags))
if (!PyArg_ParseTuple(args, "OOOl", &fromPlayerObj, &toPlayerListObj, &message, &msgFlags))
{
PyErr_SetString(PyExc_TypeError, "PtSendRTChat expects a ptPlayer, a list of ptPlayers, a string, and a long");
PYTHON_RETURN_ERROR;
@ -232,7 +232,25 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtSendRTChat, args, "Params: fromPlayer,toPlayer
PYTHON_RETURN_ERROR;
}
return PyLong_FromUnsignedLong(cyMisc::SendRTChat(*fromPlayer, toPlayerList, message, msgFlags));
if (PyString_Check(message))
{
char* msg = PyString_AsString(message);
return PyLong_FromUnsignedLong(cyMisc::SendRTChat(*fromPlayer, toPlayerList, msg, msgFlags));
}
else if (PyUnicode_Check(message))
{
Py_ssize_t size = PyUnicode_GetSize(message);
wchar_t* msg = TRACKED_NEW wchar_t[size + 1]; msg[size] = 0;
PyUnicode_AsWideChar((PyUnicodeObject*)message, msg, size);
UInt32 retval = cyMisc::SendRTChat(*fromPlayer, toPlayerList, msg, msgFlags);
DEL(msg);
return PyLong_FromUnsignedLong(retval);
}
else
{
PyErr_SetString(PyExc_TypeError, "PtSendRTChat expects a ptPlayer, a list of ptPlayers, a string, and a long");
PYTHON_RETURN_ERROR;
}
}
PYTHON_GLOBAL_METHOD_DEFINITION(PtSendKIMessage, args, "Params: command,value\nSends a command message to the KI frontend.\n"

Loading…
Cancel
Save