std::list<Socket*> socketList;
int control;
fd_set fSet;
fd_set rSet;
sockaddr_in my_addr;
struct timeval lastSleep;
class Player
{ public:
string name;
Socket connection;
};
// ****************************************************************************
// SocketMud II Copyright 2004 Brian Graversen
// ****************************************************************************
// Revision History
// —————-
// 19/01/04) Initial SocketMud II code released
// ****************************************************************************
// This product can be used freely as long as this copyright header remains
// intact. This header may not be removed or changed, and any work released
// based on this code must contain this header information in all files.
// ****************************************************************************
#include "server.h"
#include <string>
struct players {
std::string name;
Socket *connection;
} player [100];
int compare (socket *psocket, number) {
if (psocket = player[number].connection) {
return 1;}
return 0;
}
int main(int argc, char** argv) {
Server *mServer = new Server();
int port;
switch(argc) {
case 2:
port = atoi(argv[1]);
if (port < 1024 || port > 9999) {
printf("[port] must be between 1024 and 9999\n");
return 1;
}
break;
default:
printf("Syntax: %s [port]\n", argv[0]);
return 1;
}
mServer->Connect(port);
while(1) {
// poll all sockets for incoming data
mServer->PollSockets();
std::list<Socket*> socketList = mServer->GetSocketList();
std::list<Socket*>::iterator iSocket;
Socket *pSocket;
// echo everything that each socket has sent to us
for (iSocket = socketList.begin(); iSocket != socketList.end(); ) {
pSocket = *iSocket++;
compare (pSocket, 1);
pSocket->Write(pSocket->GetInBuffer());
pSocket->ClrInBuffer();
}
// flush all outgoing data
mServer->FlushSockets();
// sleep the rest of the pulse
mServer->Sleep(5);
}
return 1;
}
int compare (socket *psocket, number) {
if (psocket = player[number].connection) {
return 1;}
return 0;
}
int compare (socket *psocket, number) {
if (psocket = player[number].connection) {
return 1;
}
return 0;
}
struct players {
std::string name;
Socket *connection;
} player [100];
struct product {
int weight;
float price;
} apple, banana, melon;
The problem is if I declare the structure after the main function, I can't use it in the main function, or call any functions that use the Socket datatype. How can I make a usable structure of player information that contains their socket? Thanks in advance for your help.