From 9ad7ef34209ba6887cd3102887748098a1ce8ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Thu, 22 Nov 2012 01:54:29 +0000 Subject: XFire: Status messages fixes and logic improvements. Broken option for UTF8 nicks and statuses "%s playing %s" -> "%s is playing %s" git-svn-id: http://svn.miranda-ng.org/main/trunk@2427 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Xfire/src/Xfire_base.cpp | 62 ++++++++++++++ protocols/Xfire/src/Xfire_base.h | 4 + protocols/Xfire/src/Xfire_game.cpp | 6 +- protocols/Xfire/src/buddylist.cpp | 6 +- protocols/Xfire/src/main.cpp | 169 ++++++++++++++++--------------------- 5 files changed, 144 insertions(+), 103 deletions(-) (limited to 'protocols') diff --git a/protocols/Xfire/src/Xfire_base.cpp b/protocols/Xfire/src/Xfire_base.cpp index ac8659901f..a53ab04613 100644 --- a/protocols/Xfire/src/Xfire_base.cpp +++ b/protocols/Xfire/src/Xfire_base.cpp @@ -127,6 +127,43 @@ void Xfire_base::readStringfromDB(char*name,unsigned int dbid,int id,char**to) } } +//liest einen stringval aus der db und setzt einen string für +void Xfire_base::readUtf8StringfromDB(char*name,unsigned int dbid,char**to) +{ + //keine quelle, kein ziel? dann nix machen + if(name==NULL||to==NULL) + return; + + //wert aus der dblesen + sprintf_s(temp,128,"%s_%i",name,dbid); + if(!DBGetContactSettingUTF8String(NULL, protocolname, temp,&dbv)) + { + //string setzen + setString(dbv.pszVal,to); + //dbval wieder freigeben + DBFreeVariant(&dbv); + } +} + +//liest einen stringval aus der db welches unterid hat und setzt einen string für +void Xfire_base::readUtf8StringfromDB(char*name,unsigned int dbid,int id,char**to) +{ + //keine quelle, kein ziel? dann nix machen + if(name==NULL||to==NULL) + return; + + //wert aus der dblesen + sprintf_s(temp,128,"%s_%i_%i",name,dbid,id); + if(!DBGetContactSettingUTF8String(NULL, protocolname, temp,&dbv)) + { + //string setzen + setString(dbv.pszVal,to); + //dbval wieder freigeben + DBFreeVariant(&dbv); + } +} + + //schreibt einen stringval in die db welche unterid hat void Xfire_base::writeStringtoDB(char*name,unsigned int dbid,int id,char*val) { @@ -151,6 +188,31 @@ void Xfire_base::writeStringtoDB(char*name,unsigned int dbid,char*val) DBWriteContactSettingString(NULL, protocolname, temp,val); } +//schreibt einen stringval in die db welche unterid hat +void Xfire_base::writeUtf8StringtoDB(char*name,unsigned int dbid,int id,char*val) +{ + //keine quelle, kein ziel? dann nix machen + if(name==NULL||val==NULL) + return; + + //wert aus der dblesen + sprintf_s(temp,128,"%s_%i_%i",name,dbid,id); + DBWriteContactSettingUTF8String(NULL, protocolname, temp,val); +} + +//schreibt einen stringval in die db welche unterid hat +void Xfire_base::writeUtf8StringtoDB(char*name,unsigned int dbid,char*val) +{ + //keine quelle, kein ziel? dann nix machen + if(name==NULL||val==NULL) + return; + + //wert aus der dblesen + sprintf_s(temp,128,"%s_%i",name,dbid); + DBWriteContactSettingUTF8String(NULL, protocolname, temp,val); +} + + //schreibt einen bytewert in die db void Xfire_base::writeBytetoDB(char*name,unsigned int dbid,int val) { diff --git a/protocols/Xfire/src/Xfire_base.h b/protocols/Xfire/src/Xfire_base.h index 5753e631c4..248982b85f 100644 --- a/protocols/Xfire/src/Xfire_base.h +++ b/protocols/Xfire/src/Xfire_base.h @@ -49,12 +49,16 @@ public: void appendString(char*from,char**to); void readStringfromDB(char*name,unsigned int dbid,char**to); void readStringfromDB(char*name,unsigned int dbid,int id,char**to); + void readUtf8StringfromDB(char*name,unsigned int dbid,char**to); + void readUtf8StringfromDB(char*name,unsigned int dbid,int id,char**to); unsigned char readBytefromDB(char*name,unsigned int dbid,int defaultval=0); unsigned int readWordfromDB(char*name,unsigned int dbid,int defaultval=0); BOOL removeDBEntry(char*name,unsigned int dbid); BOOL removeDBEntry(char*name,unsigned int dbid,int id2); void writeStringtoDB(char*name,unsigned int dbid,int id,char*val); void writeStringtoDB(char*name,unsigned int dbid,char*val); + void writeUtf8StringtoDB(char*name,unsigned int dbid,int id,char*val); + void writeUtf8StringtoDB(char*name,unsigned int dbid,char*val); void writeBytetoDB(char*name,unsigned int dbid,int val); void writeWordtoDB(char*name,unsigned int dbid,int val); void strtolower(char*); diff --git a/protocols/Xfire/src/Xfire_game.cpp b/protocols/Xfire/src/Xfire_game.cpp index 10ae7bc783..835c8e6aa0 100644 --- a/protocols/Xfire/src/Xfire_game.cpp +++ b/protocols/Xfire/src/Xfire_game.cpp @@ -328,8 +328,8 @@ void Xfire_game::readFromDB(unsigned dbid) this->notinstartmenu=this->readBytefromDB("notinstartmenu",this->id,0); this->noicqstatus=this->readBytefromDB("gamenostatus",this->id,0); this->readStringfromDB("gameextraparams",this->id,&this->extraparams); - this->readStringfromDB("customgamename",this->id,&this->customgamename); - this->readStringfromDB("statusmsg",this->id,&this->statusmsg); + this->readStringfromDB("customgamename",this->id,&this->customgamename); + this->readUtf8StringfromDB("statusmsg",this->id,&this->statusmsg); //mehrere pfade int size=this->readWordfromDB("gamemulti",dbid,0); @@ -406,7 +406,7 @@ void Xfire_game::writeToDB(unsigned dbid) else //wenn nicht eintrag aus db löschen this->removeDBEntry("customgamename",this->id); if(this->statusmsg!=0) - this->writeStringtoDB("statusmsg",this->id,this->statusmsg); + this->writeUtf8StringtoDB("statusmsg",this->id,this->statusmsg); else //wenn nicht eintrag aus db löschen this->removeDBEntry("statusmsg",this->id); diff --git a/protocols/Xfire/src/buddylist.cpp b/protocols/Xfire/src/buddylist.cpp index ea7e264502..b26d07266a 100644 --- a/protocols/Xfire/src/buddylist.cpp +++ b/protocols/Xfire/src/buddylist.cpp @@ -37,7 +37,7 @@ #include "baseProtocol.h" extern HANDLE handlingBuddys(xfirelib::BuddyListEntry *entry, int clan=0,char* group=NULL,BOOL dontscan=FALSE); -extern void setBuddyStatusMsg(xfirelib::BuddyListEntry *entry,std::string statusmsg); +extern void setBuddyStatusMsg(xfirelib::BuddyListEntry *entry); namespace xfirelib { @@ -315,8 +315,8 @@ namespace xfirelib { } else { - entry->statusmsg = status->msgs->at(i).c_str(); - setBuddyStatusMsg(entry,entry->statusmsg); //auf eine funktion reduziert, verringert cpuauslastung und beseitigt das + entry->statusmsg = status->msgs->at(i); + setBuddyStatusMsg(entry); //auf eine funktion reduziert, verringert cpuauslastung und beseitigt das //das problem der fehlenden statusmsg } } diff --git a/protocols/Xfire/src/main.cpp b/protocols/Xfire/src/main.cpp index f3f05cc4dd..2ffe324b89 100644 --- a/protocols/Xfire/src/main.cpp +++ b/protocols/Xfire/src/main.cpp @@ -80,6 +80,7 @@ #include "Xfire_voicechat.h" #include +#include Xfire_gamelist xgamelist; Xfire_voicechat voicechat; @@ -326,15 +327,8 @@ void XFireClient::sendmsg(char*usr,char*cmsg) { if(!client->gotBudduyList) return; - if(s.length()>100) - { - s.substr(0, 100); - - // W T F? - ///char* temp=(char*)s.c_str(); - ///*(temp+100)=0; - // W T F? - } + s = s.substr(0, 100); + SendStatusMessagePacket *packet = new SendStatusMessagePacket(); if(myClient->useutf8) @@ -548,7 +542,7 @@ void XFireClient::sendmsg(char*usr,char*cmsg) { { BuddyListEntry *entry = this->client->getBuddyList()->getBuddyBySid( ((RecvStatusMessagePacket*)content)->sids->at(i) ); if(entry) //crashbug entfernt - setBuddyStatusMsg(entry,entry->statusmsg); //auf eine funktion reduziert, verringert cpuauslastung und beseitigt das + setBuddyStatusMsg(entry); //auf eine funktion reduziert, verringert cpuauslastung und beseitigt das //das problem der fehlenden statusmsg //handlingBuddys(entry,0,NULL); } @@ -1873,7 +1867,7 @@ void CList_MakeAllOffline() //DBDeleteContactSetting(hContact, protocolname, "XStatusMsg"); //DBDeleteContactSetting(hContact, protocolname, "XStatusId"); //DBDeleteContactSetting(hContact, protocolname, "XStatusName"); - //DBDeleteContactSetting(hContact, "CList", "StatusMsg"); + DBDeleteContactSetting(hContact, "CList", "StatusMsg"); DBDeleteContactSetting(hContact, protocolname, "ServerIP"); DBDeleteContactSetting(hContact, protocolname, "Port"); DBDeleteContactSetting(hContact, protocolname, "ServerName"); @@ -1882,7 +1876,7 @@ void CList_MakeAllOffline() DBDeleteContactSetting(hContact, protocolname, "Players"); DBDeleteContactSetting(hContact, protocolname, "Passworded"); - DBWriteContactSettingString(hContact, "CList", "StatusMsg", ""); + //DBWriteContactSettingUTF8String(hContact, "CList", "StatusMsg", ""); DBDeleteContactSetting(hContact, protocolname, "XStatusMsg"); DBDeleteContactSetting(hContact, protocolname, "XStatusId"); DBDeleteContactSetting(hContact, protocolname, "XStatusName"); @@ -2684,7 +2678,7 @@ void gamedetectiont(LPVOID lparam) SendGameStatusPacket *packet = new SendGameStatusPacket(); //verscueh serverip und port zu scannen - //XFireLog("IPPort detection ...",""); + XFireLog("IPPort detection ...",""); if(GetServerIPPort(pid,myClient->client->localaddr,myClient->client->llocaladdr,&packet->ip[3],&packet->ip[2],&packet->ip[1],&packet->ip[0],&packet->port)) { @@ -2692,9 +2686,12 @@ void gamedetectiont(LPVOID lparam) { sprintf(temp,"%d.%d.%d.%d:%d",(unsigned char)packet->ip[3],(unsigned char)packet->ip[2],(unsigned char)packet->ip[1],(unsigned char)packet->ip[0],packet->port); DBWriteContactSettingString(NULL, protocolname, "ServerIP", temp); + XFireLog("Got IPPort: %s",temp); } - else + else { DBDeleteContactSetting(NULL,protocolname, "ServerIP"); + XFireLog("NO IPPort",""); + } packet->gameid=currentgame->send_gameid; if(DBGetContactSettingByte(NULL,protocolname,"sendgamestatus",1)) @@ -2703,6 +2700,8 @@ void gamedetectiont(LPVOID lparam) if(currentgame->noicqstatus!=TRUE&&DBGetContactSettingByte(NULL,protocolname,"autosetstatusmsg",0)) SetGameStatusMsg(); + } else { + XFireLog("GetServerIPPort failed",""); } delete packet; } @@ -2829,81 +2828,61 @@ static int CustomGameSetup(WPARAM wParam,LPARAM lParam) return 0; } -void setBuddyStatusMsg(BuddyListEntry *entry,string statusmsg) -{ - char status[300]; - int mystatus=ID_STATUS_ONLINE; - - if(entry==NULL) +void setBuddyStatusMsg(BuddyListEntry *entry) +{ + if (entry == NULL) return; - if(IsContactMySelf(entry->username)) + if (IsContactMySelf(entry->username)) return; - - if (entry->statusmsg.length() > 5) { - string afk = entry->statusmsg.substr(0,5); - if (afk == "(AFK)" || afk == "(ABS)") - mystatus=ID_STATUS_AWAY; - } - - //statusmsg umwandeln - char *temp = mir_utf8decode((char*)entry->statusmsg.c_str(),NULL); - if (temp==NULL) - temp=(char*)entry->statusmsg.c_str(); - - //DBDeleteContactSetting(hContact, "CList", "StatusMsg"); - DBWriteContactSettingWord(entry->hcontact, protocolname, "Status", mystatus); - - if(entry->game!=0) + + if (entry->game) { - char temp2[255]; - temp2[0]=0; - + ostringstream xstatus; DBVARIANT dbv; - if(!DBGetContactSettingString(entry->hcontact,protocolname, "RGame",&dbv)) + if (!DBGetContactSettingString(entry->hcontact, protocolname, "RGame", &dbv)) { - strcat(temp2,dbv.pszVal); - strcat(temp2," "); + xstatus << dbv.pszVal << " "; DBFreeVariant(&dbv); } - if(DBGetContactSettingByte(NULL,protocolname,"noipportinstatus",0)==0) + if (!DBGetContactSettingByte(NULL, protocolname, "noipportinstatus", 0)) { - if(!DBGetContactSettingString(entry->hcontact,protocolname, "ServerName",&dbv)) + if (!DBGetContactSettingString(entry->hcontact, protocolname, "ServerName", &dbv)) { - strcat(temp2,dbv.pszVal); + xstatus << dbv.pszVal; DBFreeVariant(&dbv); } - else + else if (!DBGetContactSettingString(entry->hcontact,protocolname, "ServerIP",&dbv)) { - if(!DBGetContactSettingString(entry->hcontact,protocolname, "ServerIP",&dbv)) - { - strcat(temp2,"("); - strcat(temp2,dbv.pszVal); - sprintf(status,":%d)",DBGetContactSettingWord(entry->hcontact, protocolname, "Port", 0)); - strcat(temp2,status); - DBFreeVariant(&dbv); - } + xstatus << "(" << dbv.pszVal << ":" << DBGetContactSettingWord(entry->hcontact, protocolname, "Port", 0) << ")"; + DBFreeVariant(&dbv); } } - - strncpy(status,temp2,97); - - if(!entry->statusmsg.empty()) - { - strcat(status," - "); - strcat(status,temp); - } - DBWriteContactSettingString(entry->hcontact, "CList", "StatusMsg", status); - DBWriteContactSettingString(entry->hcontact, protocolname, "XStatusMsg", status); + DBWriteContactSettingUTF8String(entry->hcontact, protocolname, "XStatusMsg", xstatus.str().c_str()); } else - { - DBWriteContactSettingString(entry->hcontact, "CList", "StatusMsg", temp); - DBWriteContactSettingString(entry->hcontact, protocolname, "XStatusMsg", temp); - DBWriteContactSettingByte(entry->hcontact, protocolname, "XStatusId", 1); - DBWriteContactSettingString(entry->hcontact, protocolname, "XStatusName", ""); + { + //DBWriteContactSettingByte(entry->hcontact, protocolname, "XStatusId", 1); + DBDeleteContactSetting(entry->hcontact, protocolname, "XStatusId"); + DBDeleteContactSetting(entry->hcontact, protocolname, "XStatusName"); + DBDeleteContactSetting(entry->hcontact, protocolname, "XStatusMsg"); } + + /*//statusmsg umwandeln + char *statusmsg = mir_utf8decode((char*)entry->statusmsg.c_str(),NULL); + if (statusmsg == NULL) + statusmsg = (char*)entry->statusmsg.c_str();*/ + + string afk = entry->statusmsg.substr(0, 5); + int status_id = (afk == "(AFK)" || afk == "(ABS)") ? ID_STATUS_AWAY : ID_STATUS_ONLINE; + + DBWriteContactSettingWord(entry->hcontact, protocolname, "Status", status_id); + + if (!entry->statusmsg.empty()) + DBWriteContactSettingUTF8String(entry->hcontact, "CList", "StatusMsg", entry->statusmsg.c_str()); + else + DBDeleteContactSetting(entry->hcontact, "CList", "StatusMsg"); } /*void CheckAvatar(void *ventry) @@ -2979,16 +2958,15 @@ HANDLE handlingBuddys(BuddyListEntry *entry, int clan,char*group,BOOL dontscan) hContact=entry->hcontact; - if(hContact!=0) + if (hContact!=0) { - if(strlen(entry->nick.c_str())>0&&DBGetContactSettingByte(NULL,protocolname,"shownicks",1)) - { + if (!entry->nick.empty() && DBGetContactSettingByte(NULL, protocolname, "shownicks", 1)) { char*nick=NULL; - if(myClient->useutf8) - nick=( char* )entry->nick.c_str(); + if (myClient->useutf8) + nick = ( char* )entry->nick.c_str(); else - nick=mir_utf8decode(( char* )entry->nick.c_str(),NULL); + nick = mir_utf8decode(( char* )entry->nick.c_str(),NULL); if(nick) { @@ -3002,8 +2980,7 @@ HANDLE handlingBuddys(BuddyListEntry *entry, int clan,char*group,BOOL dontscan) //DBWriteContactSettingStringUtf(hContact, protocolname, "Nick", entry->nick.c_str()); //DBWriteContactSettingUTF8String(hContact, protocolname, "Nick", ( char* )entry->nick.c_str()); - } - else + } else DBWriteContactSettingString(hContact, protocolname, "Nick", entry->username.c_str()); if(!entry->isOnline()) @@ -3013,7 +2990,7 @@ HANDLE handlingBuddys(BuddyListEntry *entry, int clan,char*group,BOOL dontscan) DBDeleteContactSetting(hContact, protocolname, "XStatusId"); DBDeleteContactSetting(hContact, protocolname, "XStatusName"); DBDeleteContactSetting(hContact, "CList", "StatusMsg"); - DBWriteContactSettingString(hContact, protocolname, "XStatusName", ""); + //DBWriteContactSettingUTF8String(hContact, protocolname, "XStatusName", ""); DBDeleteContactSetting(hContact, protocolname, "ServerIP"); DBDeleteContactSetting(hContact, protocolname, "Port"); DBDeleteContactSetting(hContact, protocolname, "VServerIP"); @@ -3087,7 +3064,7 @@ HANDLE handlingBuddys(BuddyListEntry *entry, int clan,char*group,BOOL dontscan) if(DBGetContactSettingByte(NULL,protocolname,"gamepopup",0)==1) { char temp[256]=""; - sprintf(temp,Translate("%s playing %s."), + sprintf(temp,Translate("%s is playing %s."), //ist ein nick gesetzt? (entry->nick.length()==0? //nein dann username @@ -3100,7 +3077,7 @@ HANDLE handlingBuddys(BuddyListEntry *entry, int clan,char*group,BOOL dontscan) { if((unsigned char)gameob->ip[3]!=0) { - sprintf(temp,Translate("%s playing %s on server %d.%d.%d.%d:%d."), + sprintf(temp,Translate("%s is playing %s on server %d.%d.%d.%d:%d."), //ist ein nick gesetzt? (entry->nick.length()==0? //nein dann username @@ -3177,8 +3154,8 @@ HANDLE handlingBuddys(BuddyListEntry *entry, int clan,char*group,BOOL dontscan) //DBDeleteContactSetting(hContact, "CList", "StatusMsg"); DBWriteContactSettingWord(hContact, protocolname, "Status", ID_STATUS_ONLINE); - DBWriteContactSettingString(hContact, protocolname, "XStatusName", Translate("Playing")); - setBuddyStatusMsg(entry,entry->statusmsg); + DBWriteContactSettingUTF8String(hContact, protocolname, "XStatusName", Translate("Playing")); + setBuddyStatusMsg(entry); DBWriteContactSettingByte(hContact, protocolname, "XStatusId", xgamelist.iconmngr.getGameIconId(entry->game)+2); //buddy vorher ein spielgestartet, wenn nicht sound spielen? @@ -3192,20 +3169,17 @@ HANDLE handlingBuddys(BuddyListEntry *entry, int clan,char*group,BOOL dontscan) SetIcon(hContact,(HANDLE)-1); DBDeleteContactSetting(hContact, protocolname, "ServerIP"); DBDeleteContactSetting(hContact, protocolname, "Port"); - if(strlen(entry->statusmsg.c_str())==0) - { - DBDeleteContactSetting(hContact, protocolname, "XStatusMsg"); - DBDeleteContactSetting(hContact, protocolname, "XStatusId"); - DBDeleteContactSetting(hContact, protocolname, "XStatusName"); - } + DBDeleteContactSetting(hContact, protocolname, "XStatusMsg"); + DBDeleteContactSetting(hContact, protocolname, "XStatusId"); + DBDeleteContactSetting(hContact, protocolname, "XStatusName"); DBDeleteContactSetting(hContact, protocolname, "RGame"); DBDeleteContactSetting(hContact, protocolname, "GameId"); - setBuddyStatusMsg(entry,entry->statusmsg); + setBuddyStatusMsg(entry); } } - else if(strlen(entry->statusmsg.c_str())>0) + else if (!entry->statusmsg.empty()) { - setBuddyStatusMsg(entry,entry->statusmsg); + setBuddyStatusMsg(entry); SetIcon(hContact,(HANDLE)-1); SetIcon(hContact,(HANDLE)-1,2); @@ -3233,11 +3207,11 @@ HANDLE handlingBuddys(BuddyListEntry *entry, int clan,char*group,BOOL dontscan) DBWriteContactSettingWord(hContact, protocolname, "Status", ID_STATUS_ONLINE); DBWriteContactSettingString(entry->hcontact, protocolname, "MirVer", "xfire"); if(clan>0) DBWriteContactSettingDword(hContact, protocolname, "Clan", clan); - DBWriteContactSettingString(hContact, "CList", "StatusMsg", ""); + //DBWriteContactSettingUTF8String(hContact, "CList", "StatusMsg", ""); DBDeleteContactSetting(hContact, protocolname, "XStatusMsg"); DBDeleteContactSetting(hContact, protocolname, "XStatusId"); DBDeleteContactSetting(hContact, protocolname, "XStatusName"); - //DBDeleteContactSetting(hContact, "CList", "StatusMsg"); + DBDeleteContactSetting(hContact, "CList", "StatusMsg"); DBDeleteContactSetting(hContact, protocolname, "ServerIP"); DBDeleteContactSetting(hContact, protocolname, "Port"); DBDeleteContactSetting(hContact, protocolname, "VServerIP"); @@ -3451,7 +3425,7 @@ int SetAwayMsg(WPARAM wParam, LPARAM lParam) { { strcpy(statusmessage[0],""); } - else if((wParam!=ID_STATUS_ONLINE&&wParam!=ID_STATUS_OFFLINE)&&DBGetContactSettingByte(NULL,protocolname,"nocustomaway",0)==0) + else if((wParam!=ID_STATUS_ONLINE&&wParam!=ID_STATUS_OFFLINE)/*&&DBGetContactSettingByte(NULL,protocolname,"nocustomaway",0)==0*/) { strcpy(statusmessage[1],"(AFK) Away from Keyboard"); } @@ -3464,7 +3438,8 @@ int SetAwayMsg(WPARAM wParam, LPARAM lParam) { } else if((wParam!=ID_STATUS_ONLINE&&wParam!=ID_STATUS_OFFLINE)&&DBGetContactSettingByte(NULL,protocolname,"nocustomaway",0)==0&&strlen(( char* )lParam)>0) { - strcpy(statusmessage[1],( char* )lParam); + sprintf(statusmessage[1], "(AFK) %s", (char*)lParam); + //strcpy(statusmessage[1],( char* )lParam); } else if(wParam!=ID_STATUS_ONLINE&&wParam!=ID_STATUS_OFFLINE) { @@ -3490,7 +3465,7 @@ static void SendAMAck( LPVOID param ) { DBVARIANT dbv; - if(!DBGetContactSettingString((HANDLE)param, protocolname, "XStatusMsg",&dbv)) + if(!DBGetContactSettingUTF8String((HANDLE)param, protocolname, "XStatusMsg",&dbv)) { ProtoBroadcastAck(protocolname, (HANDLE)param, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE) 1, LPARAM(dbv.pszVal)); } -- cgit v1.2.3