// Emacs style mode select -*- C++ -*-
//--------------------------------------------------------------------------
//
// Copyright(C) 2000 Simon Howard
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//--------------------------------------------------------------------------
//
// Server Program
//
// Designed to run on linux or other *nix type system
// Also includes code to make it work on djgpp w/libsocket
// although it doesnt actually work properly on my ver of djgpp
//
// By Simon Howard
//
//--------------------------------------------------------------------------

#ifndef SERV_H
#define SERV_H

#include <sys/socket.h>
#include <netinet/in.h>
#include <time.h>

#include "main.h"

#define BUFFER_SIZE 128

extern time_t startup_time;

#define MAX_CONNECTIONS 128

typedef struct connection_s connection_t;

struct connection_s
{
  int sock;
  struct in_addr remote_addr;
  char read_buffer[BUFFER_SIZE];
  boolean connected;
  int idiotcount;

  connection_t *prev, *next;       // for freelist
};

extern int total_connections;

void Disconnect(connection_t *conn);
void KickConnection(connection_t *conn, char *reason);
void WriteMessage(connection_t *conn, char *s, ...);

extern connection_t connections;   // freelist root

typedef struct
{
  char *name;
  void (*handler)(connection_t *conn, char *extra_data);
  boolean local_only;       // only localhost can run
} servercommand_t;

extern char *motd;

void CreateSocket();
void Server();

#endif /* SERV_H */
