char* DLCODESTORM::dlcs_get_filetype(char* x, char* in) { vector <string> ft; ft=dlcs_explode(".",in); ft.size(); strcpy(x,ft[ft.size()].c_str()); return x; }
int CVarSet::get_cvartype(const char * s) { vector <string> vt; vt=dlcs_explode("_",s); if(vt.size()>1) { if(dlcs_strcasecmp(vt[0].c_str(),"b")) return CVAR_BOOL; if(dlcs_strcasecmp(vt[0].c_str(),"s")) return CVAR_STRING; if(dlcs_strcasecmp(vt[0].c_str(),"c")) return CVAR_CHAR; if(dlcs_strcasecmp(vt[0].c_str(),"uc")) return CVAR_UCHAR; if(dlcs_strcasecmp(vt[0].c_str(),"i")) return CVAR_INT; if(dlcs_strcasecmp(vt[0].c_str(),"ui")) return CVAR_UINT; if(dlcs_strcasecmp(vt[0].c_str(),"l")) return CVAR_LONG; if(dlcs_strcasecmp(vt[0].c_str(),"ul")) return CVAR_ULONG; if(dlcs_strcasecmp(vt[0].c_str(),"f")) return CVAR_FLOAT; } return CVAR_NULL; }
bool CVarSet::bLoad(void) { FILE *fp; char In[256]; char temp[1024]; float f; vector <string> lin; fp=fopen(filename.c_str(),"rt"); if(!fp) return false; while(fgets(In,255,fp)) { In[strlen(In)-1]=0; lin = dlcs_explode("=",In); if(lin.size()>1) { set_cvar(lin[0].c_str(),(char *)lin[1].c_str()); } } fclose(fp); return true; }
bool CC_Data::bLoad(void) { SetToDefaults(); pLog->_Add("LOADING CONFIG FROM %s",filename.c_str()); FILE *fp; char In[256]; char temp[1024]; float f; vector <string> lin; fp=fopen(filename.c_str(),"rt"); if(!fp) return false; while(fgets(In,255,fp)) { In[strlen(In)-1]=0; lin = dlcs_explode("=",In); if(lin.size()>1) { strcpy(temp,lin[1].c_str()); if(dlcs_strcasecmp(lin[0].c_str(),"name")) { Name.assign(lin[1].c_str()); pLog->_Add(" Name [%s]",Name.c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"password")) { Password.assign(lin[1].c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"save password")) { bSavePassword=dlcs_istrue(lin[1].c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"last server")) { strcpy(ServerName,lin[1].c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"last server ip")) { strcpy(IPAddress,lin[1].c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"port")) { strcpy(Port,lin[1].c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"log")) { bLog=dlcs_istrue(temp); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"download")) { bDownload=dlcs_istrue(lin[1].c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"sound volume")) { f=atof(lin[1].c_str()); if(f>100) f=100; if(f<0) f=0; fSoundVolume=f; continue; } if(dlcs_strcasecmp(lin[0].c_str(),"music volume")) { f=atof(lin[1].c_str()); if(f>100) f=100; if(f<0) f=0; fMusicVolume=f; continue; } if(dlcs_strcasecmp(lin[0].c_str(),"sound")) { bSound=dlcs_istrue(lin[1].c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"music")) { bMusic=dlcs_istrue(lin[1].c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"master server")) { strcpy(MasterIPAddress,lin[1].c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"master server port")) { strcpy(MasterPort,lin[1].c_str()); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"fullscreen")) { bFullScreen=dlcs_istrue(temp); pLog->_Add(" bFullScreen [%d]",bFullScreen); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"screen width")) { ScreenWidth=atoi(lin[1].c_str()); pLog->_Add(" ScreenWidth [%d]",ScreenWidth); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"screen height")) { ScreenHeight=atoi(lin[1].c_str()); pLog->_Add(" ScreenHeight [%d]",ScreenHeight); continue; } if(dlcs_strcasecmp(lin[0].c_str(),"screen colors")) { ScreenColors=atoi(lin[1].c_str()); pLog->_Add(" ScreenColors [%d]",ScreenColors); continue; } } } fclose(fp); if(bSavePassword==false) { Password.clear(); bSave(); } return true; }
string DLCODESTORM::dlcs_get_webpage(string url) { string rstr, host, page; page.clear(); string uri; string vars; vector<string> strv; strv=dlcs_explode("?",url); if(strv.size()>1) { url=strv[0]; vars=strv[1]; } vector<string> strx; strx=dlcs_explode("/",url); host=strx[1]; if( (strx[0]!="http:") && (strx[0]!="https:") ) { return "You must put http: or https:"; } else { host=strx[2]; for(int i=3;i<strx.size();i++) page=page+"/"+strx[i]; } uri=host+page; // cout << host << endl; int s, error; struct sockaddr_in addr; if((s = socket(AF_INET,SOCK_STREAM,0))<0) { // cout<<"Error 01: creating socket failed!\n"; close(s); return 1; } addr.sin_family = AF_INET; char ip[1024]; memset(ip,0,1024); strcpy(ip,dlcs_dns_lookup(host).c_str()); // cout << "IP:" << ip << endl; addr.sin_addr.s_addr = inet_addr(ip); addr.sin_port = htons(80); error = connect(s,(sockaddr*)&addr,sizeof(addr)); if(error!=0) { rstr= "Error: conecting to server failed!"; close(s); return rstr; } page=page+"?"+vars; string get_string = "GET "+page+" HTTP/1.1\r\nHost: "+host+"\r\n"; //get_string=get_string+"Content-Type: application/x-www-form-urlencoded\r\n"; get_string=get_string+"Connection: close\r\n\r\n"; // if(vars.length()) get_string=get_string+"\r\n"+vars+"\r\n"; // cout << get_string << endl; // cout << "***************************************************************" << endl; int x=get_string.length(); char msg[x]; strcpy(msg,get_string.c_str()); char answ[1024]; send(s,msg,sizeof(msg),0); ssize_t len; bool endofheader=0; while((len = recv(s, answ, 1024, 0)) > 0) for(int zz=0;zz<len;zz++) { if(!endofheader) { if(answ[zz]=='<') { if(answ[zz+1]=='!') { endofheader=true; rstr+=answ[zz]; } } } else rstr+=answ[zz]; } close(s); return rstr; }