Skip to content

Commit df352a2

Browse files
committed
actually catch the errors, closes #37
1 parent 9679a5f commit df352a2

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

QtLxBTSC/PluginHelper.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ std::tuple<int, QString, QString> PluginHelper::getTab(int tabIndex) const
168168
return { 0, "", "" };
169169
}
170170

171-
int PluginHelper::getServerDefaultChannel(uint64 serverConnectionHandlerID)
171+
uint64 PluginHelper::getServerDefaultChannel(uint64 serverConnectionHandlerID)
172172
{
173173
// first need server channel list
174174
uint64* channelList;
@@ -184,7 +184,7 @@ int PluginHelper::getServerDefaultChannel(uint64 serverConnectionHandlerID)
184184
if (res == 1)
185185
{
186186
// free the array and return id of default channel
187-
int channelid = channelList[i];
187+
uint64 channelid = channelList[i];
188188
free(channelList);
189189
return channelid;
190190
}
@@ -197,11 +197,11 @@ int PluginHelper::getServerDefaultChannel(uint64 serverConnectionHandlerID)
197197

198198
void PluginHelper::getServerEmoteFileInfo(uint64 serverConnectionHandlerID)
199199
{
200-
int channelID = getServerDefaultChannel(serverConnectionHandlerID);
200+
uint64 channelID = getServerDefaultChannel(serverConnectionHandlerID);
201201
if (channelID != 0)
202202
{
203203
// request file info of emotes.json in default channel root, this will be returned in OnFileInfoEvent
204-
if (ts3Functions.requestFileInfo(serverConnectionHandlerID, channelID, "", "/emotes.json", "BetterChat_EmoteFileInfo") != ERROR_ok)
204+
if (ts3Functions.requestFileInfo(serverConnectionHandlerID, channelID, "", "/emotes.json", returnCodeEmoteFileInfo) != ERROR_ok)
205205
{
206206
ts3Functions.logMessage("Could not request server emotes.json", LogLevel_INFO, "BetterChat", 0);
207207
}
@@ -251,7 +251,7 @@ void PluginHelper::requestServerEmoteJson(uint64 serverConnectionHandlerID, uint
251251
{
252252
std::string std_download_path = filePath.toStdString();
253253
anyID res;
254-
if (ts3Functions.requestFile(serverConnectionHandlerID, channelID, "", "/emotes.json", 1, 0, std_download_path.c_str(), &res, "BetterChat_RequestEmoteFile") == ERROR_ok)
254+
if (ts3Functions.requestFile(serverConnectionHandlerID, channelID, "", "/emotes.json", 1, 0, std_download_path.c_str(), &res, returnCodeEmoteFileRequest) == ERROR_ok)
255255
{
256256
downloads.append(res);
257257
}

QtLxBTSC/PluginHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private slots:
8989
std::tuple<int, QString, QString> getCurrentTab() const;
9090
std::tuple<int, QString, QString> getTab(int tabIndex) const;
9191

92-
int getServerDefaultChannel(uint64 serverConnectionHandlerID);
92+
uint64 getServerDefaultChannel(uint64 serverConnectionHandlerID);
9393
void getServerEmoteFileInfo(uint64 serverConnectionHandlerID);
9494

9595
void requestServerEmoteJson(uint64 serverConnectionHandlerID, uint64 channelID, const QString& filePath);

QtLxBTSC/globals.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
#include "globals.h"
99

1010
struct TS3Functions ts3Functions;
11+
char returnCodeEmoteFileInfo[64];
12+
char returnCodeEmoteFileRequest[64];

QtLxBTSC/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
#include "ts3_functions.h"
1616

1717
extern struct TS3Functions ts3Functions;
18+
extern char returnCodeEmoteFileInfo[64];
19+
extern char returnCodeEmoteFileRequest[64];

QtLxBTSC/plugin.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const char* ts3plugin_name() {
3131

3232
/* Plugin version */
3333
const char* ts3plugin_version() {
34-
return "1.11";
34+
return "1.11.1";
3535
}
3636

3737
/* Plugin API version. Must be the same as the clients API major version, else the plugin fails to load. */
@@ -59,7 +59,9 @@ void ts3plugin_setFunctionPointers(const struct TS3Functions funcs) {
5959
// Init plugin
6060
int ts3plugin_init() {
6161
char pluginPath[PATH_BUFSIZE];
62-
62+
63+
ts3Functions.createReturnCode(pluginID, returnCodeEmoteFileInfo, 64);
64+
ts3Functions.createReturnCode(pluginID, returnCodeEmoteFileRequest, 64);
6365
ts3Functions.getPluginPath(pluginPath, PATH_BUFSIZE, pluginID);
6466
helper = new PluginHelper(pluginPath);
6567

@@ -167,51 +169,60 @@ void ts3plugin_onClientMoveTimeoutEvent(uint64 serverConnectionHandlerID, anyID
167169
}
168170

169171
int ts3plugin_onServerErrorEvent(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, const char* extraMessage) {
170-
171-
if (strcmp(returnCode, "BetterChat_RequestEmoteFile") == 0)
172+
173+
if (error == ERROR_ok) // on success, ignore
174+
return 1;
175+
176+
if (strcmp(returnCode, returnCodeEmoteFileRequest) == 0)
172177
{
173178
ts3Functions.logMessage(QString("Could not dowload emotes, %1").arg(errorMessage).toLatin1(), LogLevel_INFO, "BetterChat", 0);
174179
return 1;
175180
}
176-
if (strcmp(returnCode, "BetterChat_EmoteFileInfo") == 0)
181+
if (strcmp(returnCode, returnCodeEmoteFileInfo) == 0)
177182
{
178183
ts3Functions.logMessage(QString("Could not get emote fileinfo, %1").arg(errorMessage).toLatin1(), LogLevel_INFO, "BetterChat", 0);
179184
return 1;
180185
}
181186

182-
/*if(returnCode)
187+
if(returnCode)
183188
{
184189
return 1;
185-
}*/
186-
187-
ts3Functions.logMessage(errorMessage, LogLevel_INFO, "BetterChat2", 0);
190+
}
188191

189192
/* A plugin could now check the returnCode with previously (when calling a function) remembered returnCodes and react accordingly
190193
* In case of using a a plugin return code, the plugin can return:
191194
* 0: Client will continue handling this error (print to chat tab)
192195
* 1: Client will ignore this error, the plugin announces it has handled it */
193-
194196

195-
return 1;
197+
// RETURN CODES MUST HAVE PREFIX "PR:" FOR ANY OF THIS TO WORK!!!!!!!
198+
// Using createReturnCode will make a string in the format of "PR:<PluginID>:<ID>"
199+
200+
return 0;
196201
}
197202

198203
int ts3plugin_onServerPermissionErrorEvent(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, unsigned int failedPermissionID) {
199-
200-
if (strcmp(returnCode, "BetterChat_RequestEmoteFile") == 0)
204+
205+
if (error == ERROR_ok) // on success, ignore
206+
return 1;
207+
208+
if (strcmp(returnCode, returnCodeEmoteFileRequest) == 0)
201209
{
202210
ts3Functions.logMessage(QString("Could not dowload emotes, %1").arg(errorMessage).toLatin1(), LogLevel_INFO, "BetterChat", 0);
203211
return 1;
204212
}
205-
if (strcmp(returnCode, "BetterChat_EmoteFileInfo") == 0) //trying to catch i_ft_needed_file_browse_power permission error and others
213+
if (strcmp(returnCode, returnCodeEmoteFileInfo) == 0)
206214
{
207-
ts3Functions.logMessage(QString("Could not get emote fileinfo, %1").arg(errorMessage).toLatin1(), LogLevel_INFO, "BetterChat", 0); // this is hit correctly and printed to log
208-
return 1; // this should cause the client to ignore the error but it still gets printed in the chat and the user alerted!!!
215+
ts3Functions.logMessage(QString("Could not get emote fileinfo, %1").arg(errorMessage).toLatin1(), LogLevel_INFO, "BetterChat", 0);
216+
return 1;
209217
}
210218

211-
ts3Functions.logMessage(errorMessage, LogLevel_INFO, "BetterChat", 0); // log any other possible errors
219+
if (returnCode)
220+
{
221+
return 1;
222+
}
212223

213-
/* See onServerErrorEvent for return code description */
214-
return 1; // returning 1 here should make the client ignore any error but its not working?
224+
// See onServerErrorEvent for return code description
225+
return 0;
215226
}
216227

217228
// Client received a text message

0 commit comments

Comments
 (0)