bool ParseAddress(const char* iAddress, uint32* oIP, uint16* oPort, char* errbuf) { Seperator sep(iAddress, ':', 2, 250, false, 0, 0); if (sep.argnum == 1 && sep.IsNumber(1)) { *oIP = ResolveIP(sep.arg[0], errbuf); if (*oIP == 0) return false; if (oPort) *oPort = atoi(sep.arg[1]); return true; } return false; }
bool TCPConnection::Connect(const char* irAddress, uint16 irPort, char* errbuf) { if (errbuf) errbuf[0] = 0; uint32 tmpIP = ResolveIP(irAddress); if (!tmpIP) { if (errbuf) { #ifdef _WINDOWS snprintf(errbuf, TCPConnection_ErrorBufferSize, "TCPConnection::Connect(): Couldnt resolve hostname. Error: %i", WSAGetLastError()); #else snprintf(errbuf, TCPConnection_ErrorBufferSize, "TCPConnection::Connect(): Couldnt resolve hostname. Error #%i: %s", errno, strerror(errno)); #endif } return false; } return ConnectIP(tmpIP, irPort, errbuf); }
bool LoginServer::Connect() { char tmp[25]; if(database.GetVariable("loginType",tmp,sizeof(tmp)) && strcasecmp(tmp,"MinILogin") == 0){ minilogin = true; Log.Out(Logs::Detail, Logs::World_Server, "Setting World to MiniLogin Server type"); } else minilogin = false; if (minilogin && WorldConfig::get()->WorldAddress.length()==0) { Log.Out(Logs::Detail, Logs::World_Server, "**** For minilogin to work, you need to set the <address> element in the <world> section."); return false; } char errbuf[TCPConnection_ErrorBufferSize]; if ((LoginServerIP = ResolveIP(LoginServerAddress, errbuf)) == 0) { Log.Out(Logs::Detail, Logs::World_Server, "Unable to resolve '%s' to an IP.",LoginServerAddress); return false; } if (LoginServerIP == 0 || LoginServerPort == 0) { Log.Out(Logs::Detail, Logs::World_Server, "Connect info incomplete, cannot connect: %s:%d",LoginServerAddress,LoginServerPort); return false; } if (tcpc->ConnectIP(LoginServerIP, LoginServerPort, errbuf)) { Log.Out(Logs::Detail, Logs::World_Server, "Connected to Loginserver: %s:%d",LoginServerAddress,LoginServerPort); if (minilogin) SendInfo(); else SendNewInfo(); SendStatus(); zoneserver_list.SendLSZones(); return true; } else { Log.Out(Logs::Detail, Logs::World_Server, "Could not connect to login server: %s:%d %s",LoginServerAddress,LoginServerPort,errbuf); return false; } }
/* This is always called from an IO thread. Either the server socket's thread, or a * special thread we create when we make an outbound connection. */ bool TCPConnection::Process() { char errbuf[TCPConnection_ErrorBufferSize]; switch(GetState()) { case TCPS_Ready: case TCPS_Connecting: if (ConnectionType == Outgoing) { if (GetAsyncConnect()) { if (charAsyncConnect) rIP = ResolveIP(charAsyncConnect); ConnectIP(rIP, rPort); } } return(true); case TCPS_Connected: // only receive data in the connected state, no others... if (!RecvData(errbuf)) { struct in_addr in; in.s_addr = GetrIP(); //cout << inet_ntoa(in) << ":" << GetrPort() << ": " << errbuf << endl; return false; } /* we break to do the send */ break; case TCPS_Disconnecting: { //waiting for any sending data to go out... MSendQueue.lock(); if(sendbuf) { if(sendbuf_used > 0) { //something left to send, keep processing... MSendQueue.unlock(); break; } //else, send buffer is empty. safe_delete_array(sendbuf); } //else, no send buffer, we are done. MSendQueue.unlock(); } /* Fallthrough */ case TCPS_Disconnected: FinishDisconnect(); MRunLoop.lock(); pRunLoop = false; MRunLoop.unlock(); // SetState(TCPS_Ready); //reset the state in case they want to use it again... return(false); case TCPS_Closing: //I dont understand this state... case TCPS_Error: MRunLoop.lock(); pRunLoop = false; MRunLoop.unlock(); return(false); } /* we get here in connected or disconnecting with more data to send */ bool sent_something = false; if (!SendData(sent_something, errbuf)) { struct in_addr in; in.s_addr = GetrIP(); std::cout << inet_ntoa(in) << ":" << GetrPort() << ": " << errbuf << std::endl; return false; } return true; }
static CNetAddr ResolveIP(std::string ip) { return ResolveIP(ip.c_str()); }