IRC BOT problem
-
hi,
ich hab das problem wenn er bot deopt gebant und gekickt wird und das ohne lags vorsich geht. das der bot darauf nicht reagiert. obwohl er es eigendlich sollte#include <iostream> #include <stdlib.h> #include <winsock2.h> #include <windows.h> #include <string.h> #include <string> using namespace std; int startWinsock(void); int zjoin(SOCKET s,std::string chan); int zsend(SOCKET s,std::string msg); int zmsg(SOCKET s,std::string chan,std::string msg); int zkick(SOCKET s,std::string chan,std::string nick,std::string re); int znotice(SOCKET s,std::string nick,std::string msg); int zban(SOCKET s,std::string nick,std::string address,std::string chan,std::string re); int zadmintest(std::string id,std::string chan); std::string zsad(std::string strLong,std::string strS); std::string zersetz(std::string strLong,std::string strS,std::string strnew); int zmodetest(std::string chan); int zkicktest(std::string chan); std::string adminlist; std::string banlist; std::string kickpro; std::string modepro; struct database { std::string nick; std::string id; }; int main() { ::adminlist += "zasch in allchan`s~cppp in allchan`sTheLBot in allchan`sTheQBot in allchan`s"; long rc; SOCKET s; SOCKADDR_IN addr; int auth = 0; database me; me.id = "cppp"; me.nick = "pzIRC"; std::string buf,buf2,nick,id,address,mode,addresse,msg,re,chan,buf3,knick,qnet,mode2,buf4,Lkick,kbnick,kbaddress,kbchan; int io; rc=startWinsock(); s=socket(AF_INET,SOCK_STREAM,0); memset(&addr,0,sizeof(SOCKADDR_IN)); // zuerst alles auf 0 setzten addr.sin_family=AF_INET; addr.sin_port=htons(6667); // irc server port addr.sin_addr.s_addr=inet_addr("194.109.129.222"); // irc server ip rc=connect(s,(SOCKADDR*)&addr,sizeof(SOCKADDR)); zsend(s,("NICK "+me.nick+"\r\n")); zsend(s,("USER "+me.id+" 0 0 :C++ Bot\r\n")); while(1) { char cbuf[1024] = ""; rc=recv(s,cbuf,1023,0); buf = cbuf; cout<<buf; if(buf.substr(0,4) == "PING") { buf2 = "PONG "; buf2 += buf.substr(5,buf.size()); cout << buf2; zsend(s,buf2); Lkick == "0"; if(auth != 2) { zsend(s,"PRIVMSG Q@CServe.quakenet.org :AUTH DER_STIMMT NICHT"); Sleep(500); zsend(s,"MODE pzIRC +x"); auth++; } } size_t pos2; size_t pos = buf.find(" ",0); if(pos != std::string::npos) { pos++; if(buf.substr(pos,3) == "474") // BAN { chan = buf.substr(buf.find("#",0),buf.size()); chan = chan.substr(0,chan.find(" ",0)); zmsg(s,"L",("unbanall "+chan)); Sleep(900); zjoin(s,chan); } if(buf.substr(pos,3) == "473") // +i { chan = buf.substr(buf.find("#",0),buf.size()); chan = chan.substr(0,chan.find(" ",0)); zmsg(s,"L",("clearinvite "+chan)); Sleep(900); zjoin(s,chan); } if(buf.substr(pos,3) == "475") // key { chan = buf.substr(buf.find("#",0),buf.size()); chan = chan.substr(0,chan.find(" ",0)); zmsg(s,"L",("recover "+chan)); Sleep(900); zjoin(s,chan); } if(buf.substr(pos,3) == "482") // kein op { chan = buf.substr(buf.find("#",0),buf.size()); chan = chan.substr(0,chan.find(" ",0)); zmsg(s,"L",("op "+chan)); } if(buf.substr(pos,3) == "482") // nicht im chan { chan = buf.substr(buf.find("#",0),buf.size()); chan = chan.substr(0,chan.find(" ",0)); zjoin(s,chan); } if(buf.substr(pos,7) == "PRIVMSG") // PRIVMSG { nick = buf.substr(1,buf.find("!",0)); pos2 = nick.size(); pos2-=1; nick = nick.substr(0,pos2); id = buf.substr(buf.find("!",0),buf.size()); id = id.substr(1,id.find("@")); pos2 = id.size(); pos2--; id = id.substr(0,pos2); address = buf.substr(buf.find("@"),buf.size()); address = address.substr(1,address.find(" ")); pos2 = address.size(); pos2--; address = address.substr(0,pos2); pos = buf.find(address); pos += address.size(); pos += 9; chan = buf.substr(pos,buf.size()); pos = chan.find(" "); chan = chan.substr(0,pos); pos = buf.find(" :"); pos += 2; msg = buf.substr(pos,buf.size()); pos = msg.size(); pos -= 2; msg = msg.substr(0,pos); if(::adminlist.find((id+" in "+"allchan`s"),0) != std::string::npos) { if(msg[0] == '!') { buf = msg.substr(1,msg.size()); buf += "\r\n"; znotice(s,nick,("oK. Im sending:"+buf)); zsend(s,buf); if(buf.substr(0,4) == "nick") { me.nick = buf.substr(6,buf.size()); pos = me.nick.size(); pos -= 2; me.nick = me.nick.substr(0,pos); } } } if(msg.substr(0,10) == "*add_admin" && ::adminlist.find((id+" in "+"allchan`s"),0) != std::string::npos) { ::adminlist += msg.substr(12,msg.size()); znotice(s,nick,"oK."); } if(msg.substr(0,10) == "*del_admin" && ::adminlist.find((id+" in "+"allchan`s"),0) != std::string::npos) { ::adminlist = zsad(::adminlist,msg.substr(12,msg.size())); znotice(s,nick,"oK."); } if(zadmintest(id,chan) == 0 && msg == "*mode protect on") { if(zmodetest(chan) != 0) { ::modepro += (chan+"modePon"); znotice(s,nick,"oK."); } else { znotice(s,nick,"The mode is already on, idiot."); } } if(zadmintest(id,chan) == 0 && msg == "*mode protect off") { if(zmodetest(chan) == 0) { ::modepro = zsad(::modepro,(chan+"modePon")); znotice(s,nick,"oK."); } else { znotice(s,nick,"The mode is already off, idiot."); } } if(zadmintest(id,chan) == 0 && msg == "*kick protect on") { if(zkicktest(chan) != 0) { ::kickpro += (chan+"kickPon"); znotice(s,nick,"oK."); } else { znotice(s,nick,"The mode is already on, idiot."); } } if(zadmintest(id,chan) == 0 && msg == "*kick protect off") { if(zkicktest(chan) == 0) { ::kickpro = zsad(::kickpro,(chan+"kickPon")); znotice(s,nick,"oK."); } else { znotice(s,nick,"The mode is already off, idiot."); } } } if(buf.substr(pos,3) == "353") //kban { if(buf.find(kbchan,0) != std::string::npos && buf.find(kbnick,0) != std::string::npos) { Sleep(900); zban(s,kbnick,kbaddress,kbchan,"I dislike you ! ke?"); } } if(buf.substr(pos,4) == "KICK") //KICK { size_t pos3,pos4; nick = buf.substr(1,buf.find("!",0)); pos4 = nick.size(); pos4-=1; nick = nick.substr(0,pos4); id = buf.substr(buf.find("!",0),buf.size()); id = id.substr(1,id.find("@")); pos4 = id.size(); pos4--; id = id.substr(0,pos4); address = buf.substr(buf.find("@"),buf.size()); address = address.substr(1,address.find(" ")); pos4 = address.size(); pos4--; address = address.substr(0,pos4); pos3 = buf.find(address); pos3 += address.size(); pos3 += 6; chan = buf.substr(pos3,buf.size()); pos3 = chan.find(" "); chan = chan.substr(0,pos3); pos = buf.find(chan,0); pos3 += chan.size(); pos3 += 1; knick = buf.substr(pos3,buf.size()); pos3 = knick.find(" ",0); knick = knick.substr(0,pos3); if(nick != me.nick && zadmintest(id,chan) == 1 && zkicktest(chan) == 0) { if(knick == me.nick) { if(Lkick == nick) { zmsg(s,"L",("recover "+chan)); } else { zmsg(s,"L",("unbanall "+chan)); } kbnick = nick; kbaddress = address; kbchan = chan; Lkick = nick; } else { zban(s,nick,address,chan,(nick+" is not on my adminlist!")); } } } if(buf.substr(pos,4) == "MODE") //MODE { pos = buf.find(" ",0); qnet = buf.substr(0,pos); pos = qnet.find("!",0); if(pos != std::string::npos) { nick = buf.substr(1,buf.find("!",0)); pos2 = nick.size(); pos2-=1; nick = nick.substr(0,pos2); id = buf.substr(buf.find("!",0),buf.size()); id = id.substr(1,id.find("@")); pos2 = id.size(); pos2--; id = id.substr(0,pos2); address = buf.substr(buf.find("@"),buf.size()); address = address.substr(1,address.find(" ")); pos2 = address.size(); pos2--; address = address.substr(0,pos2); pos = buf.find(address); pos += address.size(); pos += 6; chan = buf.substr(pos,buf.size()); pos = chan.find(" "); chan = chan.substr(0,pos); pos = buf.find(chan,0); pos += chan.size(); pos += 1; mode = buf.substr(pos,buf.size()); pos2 = mode.size(); pos2 -= 2; mode = mode.substr(0,pos2); cout << "!" << mode << "!" << endl; if(mode == ("vbcvb-o"+me.nick)) { zmsg(s,"L",("op "+chan)); Sleep(1100); zban(s,nick,address,chan,"I dislike you ! ke?"); } if(zadmintest(id,chan) != 0 && zmodetest(chan) == 0 && mode != ("-o "+me.nick) && io != 1) { mode2 = zersetz(mode,"+","MINUS"); mode2 = zersetz(mode2,"-","PLUS"); mode2 = zersetz(mode2,"MINUS","-"); mode2 = zersetz(mode2,"PLUS","+"); zsend(s,("MODE "+chan+" "+mode2)); zban(s,nick,address,chan,"Only admins set or unset mode`s !"); } io = 0; } } } } closesocket(s); WSACleanup(); return 0; } int zsend(SOCKET s,std::string msg) { send(s,msg.c_str(),msg.size(),0); return 0; } int zjoin(SOCKET s,std::string chan) { std::string buf = "JOIN "; buf += chan; buf += "\r\n"; send(s,buf.c_str(),buf.size(),0); return 0; } int zadmintest(std::string id,std::string chan) { if(::adminlist.find((id+" in "+chan),0) != std::string::npos || ::adminlist.find((id+" in "+"allchan`s"),0) != std::string::npos) { return 0; } else { return 1; } } int zmodetest(std::string chan) { if(::modepro.find((chan+"modePon"),0) != std::string::npos) { return 0; } else { return 1; } } int zkicktest(std::string chan) { if(::kickpro.find((chan+"kickPon"),0) != std::string::npos) { return 0; } else { return 1; } } int zmsg(SOCKET s,std::string chan,std::string msg) { std::string buf = "PRIVMSG "; buf += chan; buf += " :"; buf += msg; buf += "\r\n"; send(s,buf.c_str(),buf.size(),0); return 0; } int zkick(SOCKET s,std::string chan,std::string nick,std::string re) { std::string buf = "KICK "; buf += chan; buf += " "; buf += nick; buf += " :"; buf += re; buf += "\r\n"; send(s,buf.c_str(),buf.size(),0); return 0; } int znotice(SOCKET s,std::string nick,std::string msg) { std::string buf = "NOTICE "; buf += nick; buf += " :"; buf += msg; buf += "\r\n"; send(s,buf.c_str(),buf.size(),0); return 0; } int zban(SOCKET s,std::string nick,std::string address,std::string chan,std::string re) { std::string buf = "MODE "; buf += chan; buf += " -o+b "; buf += nick; buf += " "; buf += address; buf += "\r\n"; send(s,buf.c_str(),buf.size(),0); buf = "KICK "; buf += chan; buf += " "; buf += nick; buf += " :"; buf += re; buf += "\r\n"; send(s,buf.c_str(),buf.size(),0); return 1; } int startWinsock(void) { WSADATA wsa; return WSAStartup(MAKEWORD(2,2),&wsa); } std::string zsad(std::string strLong,std::string strS) { size_t pos; std::string buf = strLong; pos = buf.find(strS,0); if(pos == std::string::npos) { return buf; } buf = strLong.substr(0,pos); pos += strS.size(); buf += strLong.substr(pos,strLong.size()); return buf; } std::string zersetz(std::string strLong,std::string strS,std::string strnew) { size_t pos; std::string buf = strLong; pos = buf.find(strS,0); if(pos == std::string::npos) { return buf; } buf = strLong.substr(0,pos); buf += strnew; pos += strS.size(); buf += strLong.substr(pos,strLong.size()); return buf; }
ich danke schon mal
-
Du glaubst nicht ernsthaft, dass sich das jemand durchliest?
Grenze das Problem durch den Debugger ein und poste nur noch die relevanten Stellen.
-
glaubst du wirklich dass sich hier irgendwer deinen ganzen dummen code durchliest?
wenn du selber gecodet hättest, wüsstest du auch, wo ungefähr was hingehört bzw was falsch ist!
-
mann, interpreter, du musst aber auch immer vor den armen unregistrierten schreiben, was?
-
bist_du_aber_bloede schrieb:
mann, interpreter, du musst aber auch immer vor den armen unregistrierten schreiben, was?
Wieso denn? War doch zeitgleich