CslGeoIP::CslGeoIP() : m_type(GEOIP_COUNTRY) { for (wxInt32 i = 0;; i++) { const char *code = GeoIP_code_by_id(i); const char *name = GeoIP_name_by_id(i); if (!code || !name) break; m_countryCodes.push_back(C2U(code)); m_countryNames.push_back(C2U(name)); } }
wxString CslGeoIP::GetCountryNameByIPnum(const unsigned long ipnum) { CslGeoIP& self = GetInstance(); if (!g_geoIP) return wxEmptyString; GeoIPRecord *r = NULL; const char *country = NULL; switch (self.m_type) { case GEOIP_COUNTRY: country = GeoIP_country_name_by_ipnum(g_geoIP, wxUINT32_SWAP_ON_LE(ipnum)); break; case GEOIP_CITY: if ((r = GeoIP_record_by_ipnum(g_geoIP, wxUINT32_SWAP_ON_LE(ipnum)))) { country = r->country_name; GeoIPRecord_delete(r); } break; } return country ? C2U(country) : wxString(wxEmptyString); }
wxString CslGeoIP::GetCountryNameByAddr(const char *host) { CslGeoIP& self = GetInstance(); if (!g_geoIP) return wxEmptyString; GeoIPRecord *r = NULL; const char *country = NULL; switch (self.m_type) { case GEOIP_COUNTRY: country = GeoIP_country_name_by_addr(g_geoIP, host); break; case GEOIP_CITY: if ((r = GeoIP_record_by_addr(g_geoIP, host))) { country = r->country_name; GeoIPRecord_delete(r); } break; } return country ? C2U(country) : wxString(wxEmptyString); }
wxString CslGeoIP::GetCityNameByIPnum(const unsigned long ipnum) { CslGeoIP& self = GetInstance(); wxString city; if (g_geoIP && self.m_type==GEOIP_CITY) { GeoIPRecord *r = GeoIP_record_by_ipnum(g_geoIP, wxUINT32_SWAP_ON_LE(ipnum)); if (r) { city = C2U(r->city); GeoIPRecord_delete(r); } } return city; }
wxString CslGeoIP::GetCityNameByAddr(const char *host) { CslGeoIP& self = GetInstance(); wxString city; if (g_geoIP && self.m_type==GEOIP_CITY) { GeoIPRecord *r = GeoIP_record_by_addr(g_geoIP, host); if (r) { city = C2U(r->city); GeoIPRecord_delete(r); } } return city; }
static pascal OSErr MacCallbackGetUrl(const AppleEvent *in,AppleEvent *out,long ptr) { Size l=0; OSErr err=noErr; DescType type=typeChar; if ((err=AESizeOfParam(in,keyDirectObject,&type,&l))==noErr && l) { char buf[l+1]; if ((err=AEGetParamPtr(in,keyDirectObject,type,0,&buf,l,&l))==noErr && l) { buf[l]=0; const CslApp& app=::wxGetApp(); app.IpcCall(C2U(buf),app.GetTopWindow()); } } return noErr; }
bool CslIpcConnection::OnPoke(const wxString& topic, const wxString& item, #if wxCHECK_VERSION(2, 9, 0) const void *data, size_t size, #else wxChar *data, int size, #endif wxIPCFormat format) { if (m_evtHandler && topic==CSL_IPC_TOPIC && format==wxIPC_PRIVATE && size<512) { CslCharBuffer buf(size, (char*)data); CslIpcEvent evt(CslIpcEvent::IPC_COMMAND, C2U(buf)); ::wxPostEvent(m_evtHandler, evt); } return wxConnection::OnPoke(topic, item, data, size, format); }
bool CslGameAssaultCube::ParseDefaultPong(ucharbuf& buf, CslServerInfo& info) const { wxInt32 i, l, q; char text[MAXSTRLEN]; bool wasfull=info.IsFull(); if ((wxUint32)getint(buf)!=m_fourcc) return false; q=getint(buf); if (q==AC_EXTPING_SERVERINFO) loopi(2) getint(buf); info.Protocol=getint(buf); info.Version=GetVersionName(info.Protocol); wxInt32 mode=getint(buf); info.GameMode=GetModeName(mode); i=getint(buf); if (info.HasRegisteredEvent(CslServerEvents::EVENT_EMPTY) && info.Players>0 && !i) info.SetEvents(CslServerEvents::EVENT_EMPTY); else if (info.HasRegisteredEvent(CslServerEvents::EVENT_NOT_EMPTY) && !info.Players && i>0) info.SetEvents(CslServerEvents::EVENT_NOT_EMPTY); info.Players=i; info.TimeRemain=max(0, getint(buf)); if (info.Protocol<1126) // <= 0.93 info.TimeRemain++; if (info.Protocol>=1200) // <= 1.2.0.x info.TimeRemain*=60; getstring(text, buf); info.Map=C2U(FilterCubeString(text, 1)); getstring(text, buf); info.SetDescription(C2U(FilterCubeString(text, 1))); info.PlayersMax=getint(buf); if (info.HasRegisteredEvent(CslServerEvents::EVENT_FULL) && !wasfull && info.IsFull()) info.SetEvents(CslServerEvents::EVENT_FULL); else if (info.HasRegisteredEvent(CslServerEvents::EVENT_NOT_FULL) && wasfull && !info.IsFull()) info.SetEvents(CslServerEvents::EVENT_NOT_FULL); l=info.MM; info.MMDescription.Empty(); info.MM=CSL_SERVER_OPEN; if (info.Protocol>=1128 && buf.remaining()) // >=1.0.x { i = getint(buf); wxInt32 mm = i>>PONGFLAG_MASTERMODE; if (mm==1) { if (info.HasRegisteredEvent(CslServerEvents::EVENT_PRIVATE) && CSL_MM_IS_VALID(l) && !CSL_SERVER_IS_PRIVATE(l)) info.SetEvents(CslServerEvents::EVENT_PRIVATE); info.MMDescription=wxT("P"); info.MM=CSL_SERVER_PRIVATE; } else if (mm==2) { if (info.HasRegisteredEvent(CslServerEvents::EVENT_LOCKED) && CSL_MM_IS_VALID(l) && !CSL_SERVER_IS_LOCKED(l)) info.SetEvents(CslServerEvents::EVENT_LOCKED); info.MMDescription=wxT("L"); info.MM=CSL_SERVER_LOCKED; } else info.MMDescription=wxT("O"); if (i&(1<<PONGFLAG_BANNED)) { info.MMDescription<<wxT("/BAN"); CSL_FLAG_SET(info.MM, CSL_SERVER_BAN); } if (i&(1<<PONGFLAG_BLACKLIST)) { info.MMDescription<<wxT("/BLACK"); CSL_FLAG_SET(info.MM, CSL_SERVER_BLACKLIST); } if (i&(1<<PONGFLAG_PASSWORD)) { info.MMDescription<<wxT("/PASS"); CSL_FLAG_SET(info.MM, CSL_SERVER_PASSWORD); } if (buf.remaining() && getint(buf)==q) // >=1.0.2 { switch (q) { case AC_EXTPING_SERVERINFO: // >=1.0.4 { if (getstring(text, buf)==2) { i=0; info.InfoText.Empty(); while (buf.remaining()) { getstring(text, buf); if (!*text) break; if (i++) info.InfoText<<CSL_NEWLINE_WX; if (strcmp(text, ".")) info.InfoText<<C2U(FilterCubeString(text, 1, true, false, true)); } } break; } default: break; } } }