#ifndef _H_CNET
#define _H_CNET

#include "defines.h"
#include "system.h"
#include "utils.h"

class CBot;

class CNet {
public:
  CNet (CBot *, int socket = -1);
  ~CNet (void);

  ostream &operator << (c_char);

  void writeln (c_char, ...);
  int readln (void);

  bool create_tcp (int, bool block = 0);
  bool openhost (void);
  int readsock (int, char *, size_t);
  static int readok (int);
  static int writeok (int);
  void sock_linger (int, int);
  bool bindsock (int);
  void blocksock (bool);
  u_short sock2port (int sock);
  u_long sock2addr (int sock);
  bool resolvehost (c_char);
  bool closesock (void);

  CBot *bot;
  long unsigned int bytesout;
  long unsigned int bytesin;
  time_t time_read, time_write;
  char *bufread;
  int sock;
  struct sockaddr_in sa;
  bool connecting, connected;		// connect() helpers
  int bufpos;

private:
  fstream stm;

};

#include "CBot.h"

#endif

