| 81 | } |
| 82 | |
| 83 | static PyObject* |
| 84 | Player_getAttr(Player* player, char* name) { |
| 85 | PyObject* attr = Py_None; |
| 86 | player->record->update(); |
| 87 | |
| 88 | if (strcmp(name, "id") == 0) { |
| 89 | attr = Py_BuildValue("i", player->record->playerID); |
| 90 | } |
| 91 | else if (strcmp(name, "callsign") == 0) { |
| 92 | attr = PyString_FromString(player->record->callsign.c_str()); |
| 93 | } |
| 94 | else if (strcmp(name, "team") == 0) { |
| 95 | attr = Py_BuildValue("i", player->record->team); |
| 96 | } |
| 97 | else if (strcmp(name, "position") == 0) { |
| 98 | attr = Py_BuildValue("(fff)", player->record->pos[0], player->record->pos[1], player->record->pos[2]); |
| 99 | } |
| 100 | else if (strcmp(name, "rotation") == 0) { |
| 101 | attr = Py_BuildValue("f", player->record->rot); |
| 102 | } |
| 103 | else if (strcmp(name, "ipAddr") == 0) { |
| 104 | attr = PyString_FromString(player->record->ipAddress.c_str()); |
| 105 | } |
| 106 | else if (strcmp(name, "flag") == 0) { |
| 107 | // skip the Py_None check at the end, since None is a valid return value. |
| 108 | if (player->record->currentFlag.size() == 0) { |
| 109 | return Py_None; |
| 110 | } |
| 111 | else { |
| 112 | attr = PyString_FromString(player->record->currentFlag.c_str()); |
| 113 | } |
| 114 | } |
| 115 | else if (strcmp(name, "flagHistory") == 0) { |
| 116 | attr = PyList_New(0); |
| 117 | for (unsigned int i = 0; i < player->record->flagHistory.size(); i++) { |
| 118 | bzApiString str = player->record->flagHistory[i]; |
| 119 | PyList_Append(attr, PyString_FromString(str.c_str())); |
| 120 | } |
| 121 | } |
| 122 | else if (strcmp(name, "spawned") == 0) { |
| 123 | attr = player->record->spawned ? Py_True : Py_False; |
| 124 | } |
| 125 | else if (strcmp(name, "verified") == 0) { |
| 126 | attr = player->record->verified ? Py_True : Py_False; |
| 127 | } |
| 128 | else if (strcmp(name, "global") == 0) { |
| 129 | attr = player->record->globalUser ? Py_True : Py_False; |
| 130 | } |
| 131 | else if (strcmp(name, "admin") == 0) { |
| 132 | attr = player->record->admin ? Py_True : Py_False; |
| 133 | } |
| 134 | else if (strcmp(name, "groups") == 0) { |
| 135 | attr = PyList_New(0); |
| 136 | for (unsigned int i = 0; i < player->record->groups.size(); i++) { |
| 137 | bzApiString str = player->record->groups[i]; |
| 138 | PyList_Append(attr, PyString_FromString(str.c_str())); |
| 139 | } |
| 140 | } |