#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <netdb.h>
#include <string.h>
#include <unistd.h>
#include "udanax.h"
#include "players.h"
#include "port.h"
Include dependency graph for socketbe.cxx:

Go to the source code of this file.
Defines | |
| #define | ERROR -1 |
| #define | typerequest int |
| #define | MAX_PLAYERS 25 |
Functions | |
| bool | establishprotocol (FILE *inp, FILE *outp) |
| ??? | |
| void | new_players (PLAYER player[], int *n_playersp, int block, Session *sess) |
| ??? | |
| void | leave (PLAYER player[], int *xn_players) |
| ??? | |
| int | open_sock () |
| ??? | |
| void | crash (int) |
| ??? | |
| bool | isthisusersdocument (Session *sess, Tumbler *tp) |
| ??? | |
Variables | |
| char | hostname [] |
| int | portname |
| int | fdtoplayer [32] |
| Tumbler | defaultaccount = { 0, 0, 0, 0, { 1, 1, 0, 14, 0, 0, 0, 0, 0, 0, 0 } } |
| PLAYER | player [MAX_PLAYERS] |
| int | n_players = 0 |
| fd_set | inputfds |
| int | nfds = 0 |
| int | main_socket = ERROR |
(to be defined)
Definition in file socketbe.cxx.
|
|
Definition at line 98 of file socketbe.cxx. Referenced by new_players(). |
|
|
Definition at line 100 of file socketbe.cxx. |
|
|
Definition at line 99 of file socketbe.cxx. Referenced by xanadu(). |
|
|
??? (to be defined) Definition at line 294 of file socketbe.cxx. Referenced by main().
00296 {
00297 int i;
00298
00299 L("CRASH while dealing with user %d\n", user);
00300 for (i = 0; i < 32; i++)
00301 close(i); /* BOO HISS: too many closes */
00302 exit(9);
00303 }
|
|
||||||||||||
|
??? (to be defined) Definition at line 154 of file be.cxx. References Session::errp, febelog, firstputforrequest, Session::inp, L, metachar, nulllog, Session::outp, pullc(), sendresultoutput(), and xuputstring(). Referenced by main(), and new_players().
00157 {
00158 char ch;
00159 Session tempsess;
00160
00161 if (febelog && febelog != nulllog)
00162 fprintf(febelog, "fe:\n");
00163 firstputforrequest = true;
00164
00165 /* This is the metaprotocol for the time being */
00166
00167 tempsess.inp = inp;
00168 tempsess.outp = outp;
00169 tempsess.errp = stderr;
00170
00171 while ((ch = pullc(&tempsess)) != '\n') ;
00172 while ((ch = pullc(&tempsess)) == '\n') ;
00173 if (ch == 'P' && pullc(&tempsess) == '0' && pullc(&tempsess) == '~') {
00174 xuputstring("\nP0~", tempsess.outp);
00175 sendresultoutput(&tempsess);
00176 return true;
00177 } else {
00178 xuputstring("\nP?~", tempsess.outp);
00179 sendresultoutput(&tempsess);
00180 return false;
00181 }
00182 }
|
|
||||||||||||
|
??? (to be defined)
Definition at line 313 of file socketbe.cxx. References player, tumbleraccounteq(), and user.
00314 : User's session context 00315 Tumbler *tp) 00316 { 00317 return tumbleraccounteq(tp, &(player[user].account)); 00318 } |
|
||||||||||||
|
??? (to be defined) Definition at line 225 of file socketbe.cxx. References inputfds, L, player, PLAYER, and _player::wantsout. Referenced by main().
00228 {
00229 register int i;
00230
00231 for (i = 0; i < *xn_players; i++)
00232 if (player[i].wantsout) {
00233 FD_CLR(player[i].socket, &inputfds);
00234 //OBSOLETE inputfds ^= (1 << (player[i].socket));
00235
00236 if (close(player[i].socket) != 0) {
00237 L("user %d: ", i);
00238 perror("close player.socket");
00239 }
00240 if (*xn_players > 1) {
00241 player[i] = player[*xn_players - 1];
00242 }
00243 (*xn_players)--;
00244 --i; /* since this entry is new, test again */
00245 }
00246 }
|
|
||||||||||||||||||||
|
??? (to be defined)
Definition at line 126 of file socketbe.cxx. References ERROR, establishprotocol(), fdtoplayer, Session::inp, _player::inp, inputfds, L, main_socket, max, MAX_PLAYERS, nfds, NULL, open_sock(), _player::outp, Session::outp, player, PLAYER, _player::socket, and _player::wantsout. Referenced by main().
00130 : User's session context 00131 /* array of player info structures */ 00132 /* number of players (incl comp) */ 00133 /* if nobody wants to join, wait on socket until somebody * does. */ 00134 { 00135 int s; /* temp holder for new socket */ 00136 int rc; /* # ready selected sockets */ 00137 struct sockaddr_in from; /* connection acceptor */ 00138 socklen_t fromlen = sizeof(from); 00139 struct timeval t; /* don't let select() run forever */ 00140 //UNUSED int i; 00141 //UNUSED FILE *temp; 00142 //UNUSED char devicename[100]; 00143 //UNUSED int len; 00144 //UNUSED typerequest requestinstance; 00145 int open_sock(); /* to open main socket */ 00146 00147 if (main_socket == ERROR) 00148 main_socket = open_sock(); 00149 00150 /* set up 0 second timeout for use on select() calls */ 00151 /* well it USED to be 0 seconds, but that seems too fast now !<reg sep 10 1999> */ 00152 t.tv_sec = 0L; 00153 t.tv_usec = 3L; 00154 00155 for (;;) { 00156 fd_set readfds; 00157 FD_ZERO(&readfds); 00158 FD_SET(main_socket, &readfds); 00159 //OBSOLETE readfds = 1 << main_socket; 00160 00161 t.tv_sec = 0L; 00162 t.tv_usec = 3L; 00163 if ((rc = select(32, &readfds, 0, 0, &t)) == -1) { // Wait on Main Socket 00164 perror("new_players:select"); 00165 fflush(stdout); 00166 break; 00167 } 00168 if (rc > 0 || block) { 00169 if ((s = accept(main_socket, (sockaddr *) &from, &fromlen)) < 0) { 00170 perror("new_players:accept"); 00171 fflush(stdout); 00172 break; 00173 } 00174 if (*n_playersp >= MAX_PLAYERS) { 00175 L("TOOMANY frontends: won't log another one\n"); 00176 close(s); 00177 } else { 00178 block = false; 00179 #ifndef DISTRIBUTION 00180 L("accepted connection from %d ", s); 00181 #endif 00182 /* read ttyname and open socket for it; */ 00183 00184 player[*n_playersp].socket = s; 00185 if ((player[*n_playersp].inp = fdopen(s, "r")) == NULL) { 00186 perror("fdopen(r)"); 00187 break; 00188 } 00189 if ((sess->outp = player[*n_playersp].outp = fdopen(s, "w")) == NULL) { 00190 perror("fdopen(w)"); 00191 break; 00192 } 00193 sess->inp = player[*n_playersp].inp; 00194 00195 #ifndef DISTRIBUTION 00196 L("%s\n", (char *) &(player[*n_playersp].account)); 00197 #endif 00198 if (!establishprotocol(sess->inp, sess->outp)) { 00199 break; 00200 } 00201 // getrequest(sess, &requestinstance); 00202 // getxaccount(sess, &(player[*n_playersp].account)); 00203 // logaccount(&(player[*n_playersp].account)); 00204 player[*n_playersp].wantsout = false; 00205 00206 fdtoplayer[s] = *n_playersp; 00207 FD_SET(s, &inputfds); 00208 nfds = max(s, nfds); 00209 (*n_playersp)++; 00210 break; 00211 } 00212 } else 00213 break; 00214 } 00215 } |
|
|
??? (to be defined) Definition at line 256 of file socketbe.cxx. Referenced by main(), and new_players().
00257 { /* Open the main socket. */
00258 int s;
00259 struct sockaddr_in sockaddr;
00260 //UNUSED struct hostent *host;
00261
00262 if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
00263 perror("socket()");
00264 exit(1);
00265 }
00266 /*
00267 * if ((host = gethostbyname(hostname)) == NULL) { perror("gethostbyname()");
00268 * exit(1); } */
00269 sockaddr.sin_family = AF_INET;
00270 sockaddr.sin_port = htons(portname);
00271 sockaddr.sin_addr.s_addr = /* inetaddr */ INADDR_ANY;
00272
00273 L("calling bind s = %d \n", s);
00274
00275 if (bind(s, (struct sockaddr *) &sockaddr, sizeof(sockaddr)) < 0) {
00276 perror("bind()");
00277 exit(1);
00278 }
00279 if (listen(s, 0) < 0) {
00280 perror("listen()");
00281 exit(1);
00282 }
00283 return (s);
00284 }
|
|
|
Definition at line 107 of file socketbe.cxx. |
|
|
Definition at line 106 of file socketbe.cxx. Referenced by main(), and new_players(). |
|
|
Definition at line 103 of file socketbe.cxx. Referenced by processrcfile(). |
|
|
Definition at line 111 of file socketbe.cxx. Referenced by leave(), main(), and new_players(). |
|
|
Definition at line 114 of file socketbe.cxx. Referenced by main(), and new_players(). |
|
|
Definition at line 110 of file socketbe.cxx. Referenced by decrementusers(), and main(). |
|
|
Definition at line 112 of file socketbe.cxx. Referenced by main(), and new_players(). |
|
|
Definition at line 109 of file socketbe.cxx. |
|
|
Definition at line 104 of file socketbe.cxx. Referenced by open_sock(), and processrcfile(). |
1.3.4