| 155 | } |
| 156 | |
| 157 | void TelnetConsole::process() |
| 158 | { |
| 159 | NetAddress address; |
| 160 | |
| 161 | if(mAcceptSocket != NetSocket::INVALID) |
| 162 | { |
| 163 | // ok, see if we have any new connections: |
| 164 | NetSocket newConnection; |
| 165 | newConnection = Net::accept(mAcceptSocket, &address); |
| 166 | |
| 167 | if(newConnection != NetSocket::INVALID) |
| 168 | { |
| 169 | char buffer[256]; |
| 170 | Net::addressToString(&address, buffer); |
| 171 | Con::printf("Telnet connection from %s", buffer); |
| 172 | |
| 173 | TelnetClient *cl = new TelnetClient; |
| 174 | cl->socket = newConnection; |
| 175 | cl->curPos = 0; |
| 176 | #if defined(TORQUE_SHIPPING) && defined(TORQUE_DISABLE_TELNET_CONSOLE_PASSWORD) |
| 177 | // disable the password in a ship build? WTF. lets make an error: |
| 178 | PleaseMakeSureYouKnowWhatYouAreDoingAndCommentOutThisLineIfSo. |
| 179 | #elif !defined(TORQUE_SHIPPING) && defined(TORQUE_DISABLE_TELNET_CONSOLE_PASSWORD) |
| 180 | cl->state = FullAccessConnected; |
| 181 | #else |
| 182 | cl->state = PasswordTryOne; |
| 183 | #endif |
| 184 | |
| 185 | Net::setBlocking(newConnection, false); |
| 186 | |
| 187 | const char *prompt = Con::getVariable("Con::Prompt"); |
| 188 | char connectMessage[1024]; |
| 189 | dSprintf(connectMessage, sizeof(connectMessage), |
| 190 | "Torque Telnet Remote Console\r\n\r\n%s", |
| 191 | cl->state == FullAccessConnected ? prompt : "Enter Password:"); |
| 192 | |
| 193 | Net::send(cl->socket, (const unsigned char*)connectMessage, dStrlen(connectMessage)+1); |
| 194 | cl->nextClient = mClientList; |
| 195 | mClientList = cl; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | char recvBuf[256]; |
| 200 | char reply[1024]; |
| 201 | |
| 202 | // see if we have any input to process... |
| 203 | |
| 204 | for(TelnetClient *client = mClientList; client; client = client->nextClient) |
| 205 | { |
| 206 | S32 numBytes; |
| 207 | Net::Error err = Net::recv(client->socket, (unsigned char*)recvBuf, sizeof(recvBuf), &numBytes); |
| 208 | |
| 209 | if((err != Net::NoError && err != Net::WouldBlock) || numBytes == 0) |
| 210 | { |
| 211 | Net::closeSocket(client->socket); |
| 212 | client->socket = NetSocket::INVALID; |
| 213 | continue; |
| 214 | } |