--- deliantra/server/socket/loop.C 2006/08/30 16:30:37 1.4 +++ deliantra/server/socket/loop.C 2006/09/09 21:48:29 1.5 @@ -1,7 +1,7 @@ /* * static char *rcsid_loop_c = - * "$Id: loop.C,v 1.4 2006/08/30 16:30:37 root Exp $"; + * "$Id: loop.C,v 1.5 2006/09/09 21:48:29 root Exp $"; */ /* @@ -171,151 +171,6 @@ } /** - * Handles old socket format. - */ -void Handle_Oldsocket(NewSocket *ns) -{ - int stat,i; - CommFunc command; - char buf[MAX_BUF],*cp; - object ob; - player pl; - - /* This is not the most efficient block, but keeps the code simpler - - * we basically read a byte at a time until we get a newline, error, - * or no more characters to read. - */ - do { - /* hack to disable old socket mode without creating too many conflicts */ - if (1 || ns->inbuf.len >= MAXSOCKBUF-1) { - ns->status = Ns_Dead; - LOG(llevDebug, "Old input socket sent too much data without newline\n"); - return; - } -#ifdef WIN32 /* ***win32: change oldsocket read() to recv() */ - stat = recv(ns->fd, ns->inbuf.buf + ns->inbuf.len, 1,0); - - if (stat==-1 && WSAGetLastError() !=WSAEWOULDBLOCK) { -#else - do { - stat = read(ns->fd, ns->inbuf.buf + ns->inbuf.len, 1); - } while ((stat<0) && (errno == EINTR)); - - if (stat<0 && errno != EAGAIN && errno !=EWOULDBLOCK) { -#endif - LOG(llevError, "Cannot read from socket: %s\n", strerror(errno)); - ns->status = Ns_Dead; - return; - } - if (stat == 0) return; - } while (ns->inbuf.buf[ns->inbuf.len++]!='\n'); - - ns->inbuf.buf[ns->inbuf.len]=0; - - cp = strchr((const char*)ns->inbuf.buf, ' '); - if (cp) { - /* Replace the space with a null, skip any more spaces */ - *cp++=0; - while (isspace(*cp)) cp++; - } - - /* Strip off all spaces and control characters from end of line */ - for (i=ns->inbuf.len-1; i>=0; i--) { - if (ns->inbuf.buf[i]<=32) ns->inbuf.buf[i]=0; - else break; - } - ns->inbuf.len=0; /* reset for next read */ - - /* If just a return, don't do anything */ - if (ns->inbuf.buf[0] == 0) return; - if (!strcasecmp((const char*)ns->inbuf.buf,"quit")) { - ns->status = Ns_Dead; - return; - } - if (!strcasecmp((const char*)ns->inbuf.buf, "listen")) { - if (cp) { - char *buf="Socket switched to listen mode\n"; - - free(ns->comment); - ns->comment = strdup_local(cp); - ns->old_mode = Old_Listen; - cs_write_string(ns, buf, strlen(buf)); - } else { - char *buf="Need to supply a comment/url to listen\n"; - cs_write_string(ns, buf, strlen(buf)); - } - return; - } - if (!strcasecmp((const char*)ns->inbuf.buf, "name")) { - char *cp1=NULL; - if (cp) cp1= strchr(cp, ' '); - if (cp1) { - *cp1++ = 0; - while (isspace(*cp1)) cp1++; - } - if (!cp || !cp1) { - char *buf="Need to provide a name/password to name\n"; - cs_write_string(ns, buf, strlen(buf)); - return; - } - - if (verify_player(cp, cp1)==0) { - char *buf="Welcome back\n"; - free(ns->comment); - ns->comment = strdup_local(cp); - ns->old_mode = Old_Player; - cs_write_string(ns, buf, strlen(buf)); - } - else if (verify_player(cp, cp1)==2) { - ns->password_fails++; - if (ns->password_fails >= MAX_PASSWORD_FAILURES) { - char *buf="You failed to log in too many times, you will now be kicked.\n"; - LOG(llevInfo, "A player connecting from %s in oldsocketmode has been dropped for password failure\n", - ns->host); - cs_write_string(ns, buf, strlen(buf)); - ns->status = Ns_Dead; - } - else { - char *buf="Could not login you in. Check your name and password.\n"; - cs_write_string(ns, buf, strlen(buf)); - } - } - else { - char *buf="Could not login you in. Check your name and password.\n"; - cs_write_string(ns, buf, strlen(buf)); - } - return; - } - - command = find_oldsocket_command((char*)ns->inbuf.buf); - if (!command && ns->old_mode==Old_Player) { - command = find_oldsocket_command2((char*)ns->inbuf.buf); - } - if (!command) { - snprintf(buf, sizeof(buf), "Could not find command: %s\n", ns->inbuf.buf); - cs_write_string(ns, buf, strlen(buf)); - return; - } - - /* This is a bit of a hack, but works. Basically, we make some - * fake object and player pointers and give at it. - * This works as long as the functions we are calling don't need - * to do anything to the object structure (ie, they are only - * outputting information and not actually updating anything much.) - */ - ob.contr = &pl; - pl.ob = &ob; - ob.type = PLAYER; - pl.listening = 10; - pl.socket = *ns; - pl.outputs_count = 1; - ob.name = ns->comment; - - command(&ob, cp); -} - - -/** * Handle client input. * * HandleClient is actually not named really well - we only get here once @@ -340,23 +195,7 @@ return; } - if (ns->status == Ns_Old) { - Handle_Oldsocket(ns); - return; - } i=SockList_ReadPacket(ns->fd, &ns->inbuf, MAXSOCKBUF-1); - /* Special hack - let the user switch to old mode if in the Ns_Add - * phase. Don't demand they add in the special length bytes - */ - if (ns->status == Ns_Add) { - if (!strncasecmp((const char*)ns->inbuf.buf,"oldsocketmode", 13)) { - ns->status = Ns_Old; - ns->inbuf.len=0; - cs_write_string(ns, "Switched to old socket mode\n", 28); - LOG(llevDebug,"Switched socket to old socket mode\n"); - return; - } - } if (i<0) { #ifdef ESRV_DEBUG