Skip to content

Commit

Permalink
actually catch the errors, closes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Luch00 committed Oct 28, 2018
1 parent 9679a5f commit df352a2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
10 changes: 5 additions & 5 deletions QtLxBTSC/PluginHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ std::tuple<int, QString, QString> PluginHelper::getTab(int tabIndex) const
return { 0, "", "" };
}

int PluginHelper::getServerDefaultChannel(uint64 serverConnectionHandlerID)
uint64 PluginHelper::getServerDefaultChannel(uint64 serverConnectionHandlerID)
{
// first need server channel list
uint64* channelList;
Expand All @@ -184,7 +184,7 @@ int PluginHelper::getServerDefaultChannel(uint64 serverConnectionHandlerID)
if (res == 1)
{
// free the array and return id of default channel
int channelid = channelList[i];
uint64 channelid = channelList[i];
free(channelList);
return channelid;
}
Expand All @@ -197,11 +197,11 @@ int PluginHelper::getServerDefaultChannel(uint64 serverConnectionHandlerID)

void PluginHelper::getServerEmoteFileInfo(uint64 serverConnectionHandlerID)
{
int channelID = getServerDefaultChannel(serverConnectionHandlerID);
uint64 channelID = getServerDefaultChannel(serverConnectionHandlerID);
if (channelID != 0)
{
// request file info of emotes.json in default channel root, this will be returned in OnFileInfoEvent
if (ts3Functions.requestFileInfo(serverConnectionHandlerID, channelID, "", "/emotes.json", "BetterChat_EmoteFileInfo") != ERROR_ok)
if (ts3Functions.requestFileInfo(serverConnectionHandlerID, channelID, "", "/emotes.json", returnCodeEmoteFileInfo) != ERROR_ok)
{
ts3Functions.logMessage("Could not request server emotes.json", LogLevel_INFO, "BetterChat", 0);
}
Expand Down Expand Up @@ -251,7 +251,7 @@ void PluginHelper::requestServerEmoteJson(uint64 serverConnectionHandlerID, uint
{
std::string std_download_path = filePath.toStdString();
anyID res;
if (ts3Functions.requestFile(serverConnectionHandlerID, channelID, "", "/emotes.json", 1, 0, std_download_path.c_str(), &res, "BetterChat_RequestEmoteFile") == ERROR_ok)
if (ts3Functions.requestFile(serverConnectionHandlerID, channelID, "", "/emotes.json", 1, 0, std_download_path.c_str(), &res, returnCodeEmoteFileRequest) == ERROR_ok)
{
downloads.append(res);
}
Expand Down
2 changes: 1 addition & 1 deletion QtLxBTSC/PluginHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private slots:
std::tuple<int, QString, QString> getCurrentTab() const;
std::tuple<int, QString, QString> getTab(int tabIndex) const;

int getServerDefaultChannel(uint64 serverConnectionHandlerID);
uint64 getServerDefaultChannel(uint64 serverConnectionHandlerID);
void getServerEmoteFileInfo(uint64 serverConnectionHandlerID);

void requestServerEmoteJson(uint64 serverConnectionHandlerID, uint64 channelID, const QString& filePath);
Expand Down
2 changes: 2 additions & 0 deletions QtLxBTSC/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
#include "globals.h"

struct TS3Functions ts3Functions;
char returnCodeEmoteFileInfo[64];
char returnCodeEmoteFileRequest[64];
2 changes: 2 additions & 0 deletions QtLxBTSC/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
#include "ts3_functions.h"

extern struct TS3Functions ts3Functions;
extern char returnCodeEmoteFileInfo[64];
extern char returnCodeEmoteFileRequest[64];
49 changes: 30 additions & 19 deletions QtLxBTSC/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const char* ts3plugin_name() {

/* Plugin version */
const char* ts3plugin_version() {
return "1.11";
return "1.11.1";
}

/* Plugin API version. Must be the same as the clients API major version, else the plugin fails to load. */
Expand Down Expand Up @@ -59,7 +59,9 @@ void ts3plugin_setFunctionPointers(const struct TS3Functions funcs) {
// Init plugin
int ts3plugin_init() {
char pluginPath[PATH_BUFSIZE];


ts3Functions.createReturnCode(pluginID, returnCodeEmoteFileInfo, 64);
ts3Functions.createReturnCode(pluginID, returnCodeEmoteFileRequest, 64);
ts3Functions.getPluginPath(pluginPath, PATH_BUFSIZE, pluginID);
helper = new PluginHelper(pluginPath);

Expand Down Expand Up @@ -167,51 +169,60 @@ void ts3plugin_onClientMoveTimeoutEvent(uint64 serverConnectionHandlerID, anyID
}

int ts3plugin_onServerErrorEvent(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, const char* extraMessage) {

if (strcmp(returnCode, "BetterChat_RequestEmoteFile") == 0)

if (error == ERROR_ok) // on success, ignore
return 1;

if (strcmp(returnCode, returnCodeEmoteFileRequest) == 0)
{
ts3Functions.logMessage(QString("Could not dowload emotes, %1").arg(errorMessage).toLatin1(), LogLevel_INFO, "BetterChat", 0);
return 1;
}
if (strcmp(returnCode, "BetterChat_EmoteFileInfo") == 0)
if (strcmp(returnCode, returnCodeEmoteFileInfo) == 0)
{
ts3Functions.logMessage(QString("Could not get emote fileinfo, %1").arg(errorMessage).toLatin1(), LogLevel_INFO, "BetterChat", 0);
return 1;
}

/*if(returnCode)
if(returnCode)
{
return 1;
}*/

ts3Functions.logMessage(errorMessage, LogLevel_INFO, "BetterChat2", 0);
}

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


return 1;
// RETURN CODES MUST HAVE PREFIX "PR:" FOR ANY OF THIS TO WORK!!!!!!!
// Using createReturnCode will make a string in the format of "PR:<PluginID>:<ID>"

return 0;
}

int ts3plugin_onServerPermissionErrorEvent(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, unsigned int failedPermissionID) {

if (strcmp(returnCode, "BetterChat_RequestEmoteFile") == 0)

if (error == ERROR_ok) // on success, ignore
return 1;

if (strcmp(returnCode, returnCodeEmoteFileRequest) == 0)
{
ts3Functions.logMessage(QString("Could not dowload emotes, %1").arg(errorMessage).toLatin1(), LogLevel_INFO, "BetterChat", 0);
return 1;
}
if (strcmp(returnCode, "BetterChat_EmoteFileInfo") == 0) //trying to catch i_ft_needed_file_browse_power permission error and others
if (strcmp(returnCode, returnCodeEmoteFileInfo) == 0)
{
ts3Functions.logMessage(QString("Could not get emote fileinfo, %1").arg(errorMessage).toLatin1(), LogLevel_INFO, "BetterChat", 0); // this is hit correctly and printed to log
return 1; // this should cause the client to ignore the error but it still gets printed in the chat and the user alerted!!!
ts3Functions.logMessage(QString("Could not get emote fileinfo, %1").arg(errorMessage).toLatin1(), LogLevel_INFO, "BetterChat", 0);
return 1;
}

ts3Functions.logMessage(errorMessage, LogLevel_INFO, "BetterChat", 0); // log any other possible errors
if (returnCode)
{
return 1;
}

/* See onServerErrorEvent for return code description */
return 1; // returning 1 here should make the client ignore any error but its not working?
// See onServerErrorEvent for return code description
return 0;
}

// Client received a text message
Expand Down

0 comments on commit df352a2

Please sign in to comment.