Subversion Repositories Kolibri OS

Rev

Rev 298 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <errno.h>
  6. #include "i_system.h"
  7. #include "d_event.h"
  8. #include "d_net.h"
  9. #include "m_argv.h"
  10. #include "doomstat.h"
  11. #include "i_net.h"
  12.  
  13. #ifdef DLHEAP
  14.  
  15. void* _cdecl dlmalloc(size_t);
  16. void  _cdecl dlfree(void*);
  17. void _cdecl mf_init();
  18.  
  19. #define malloc dlmalloc
  20. #define free dlfree
  21. #define realloc dlrealloc
  22.  
  23. #endif
  24.  
  25. #ifndef B_HOST_IS_LENDIAN
  26. #define B_HOST_IS_LENDIAN 1
  27. #endif
  28. #if !defined(sparc) && B_HOST_IS_LENDIAN
  29. #ifndef ntohl
  30. #define ntohl(x) \
  31.         ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
  32.                              (((unsigned long int)(x) & 0x0000ff00U) <<  8) | \
  33.                              (((unsigned long int)(x) & 0x00ff0000U) >>  8) | \
  34.                              (((unsigned long int)(x) & 0xff000000U) >> 24)))
  35. #endif
  36.  
  37. #ifndef ntohs
  38. #define ntohs(x) \
  39.         ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
  40.                               (((unsigned short int)(x) & 0xff00) >> 8)))
  41. #endif
  42.          
  43. #ifndef htonl
  44. #define htonl(x) ntohl(x)
  45. #endif
  46. #ifndef htons
  47. #define htons(x) ntohs(x)
  48. #endif
  49. #endif
  50.  
  51. void    NetSend (void);
  52. int NetListen (void);
  53.  
  54.  
  55. //
  56. // NETWORKING
  57. //
  58.  
  59. #ifndef IPPORT_USERRESERVED
  60. #define IPPORT_USERRESERVED     5000
  61. #endif
  62.  
  63. int     DOOMPORT = (IPPORT_USERRESERVED+0x1d);
  64. int     sendsocket[MAXNETNODES];
  65. int     insocket;
  66.  
  67. void    (*netget) (void);
  68. void    (*netsend) (void);
  69.  
  70. static int first_user_port=IPPORT_USERRESERVED+0x1D+0x10;
  71.  
  72. /**********
  73. int GetAvailPort(void)
  74. {
  75.  int i,d0;
  76.  //for(i=0;i<1024;i++)
  77.  //{
  78.  // __asm__ __volatile__(
  79.  //     "int $0x40"
  80.  //     :"=a"(d0)
  81.  //     :"0"(53),"b"(9),"c"(first_user_port+i));
  82.  // if(d0==1) return i+first_user_port;
  83.  //}
  84.  I_Error("Unable to get new port\n");
  85.  return -1;
  86. }
  87. **********/
  88.  
  89. int CreateInputUDPsocket(void)
  90. {
  91.  int d0=0;
  92.  //__asm__ __volatile__(
  93.  //    "int $0x40"
  94.  //    :"=a"(d0)
  95.  //    :"0"(53),"b"(1),"c"(DOOMPORT),"d"(0),"S"(0));
  96.  //if(d0==0xffffffff)
  97.  //{
  98.   I_Error("Unable to create socket\n");
  99.  //}
  100.  return d0;
  101. }
  102.  
  103. int CreateOutputUDPSocket(int remote_ip)
  104. {
  105.  int d0;
  106.  int p;
  107. // p=GetAvailPort();
  108. // __asm__ __volatile__(
  109. //     "int $0x40"
  110. //     :"=a"(d0)
  111. //     :"0"(53),"b"(0),"c"(p),"d"(DOOMPORT),"S"(remote_ip));
  112. // if(d0==0xffffffff)
  113. // {
  114.   I_Error("Unable to create output socket\n");
  115. // }
  116.  return d0;
  117. }
  118.  
  119. //
  120. // PacketSend
  121. //
  122. void PacketSend (void)
  123. {
  124.  int c;
  125.  doomdata_t sw;
  126.  
  127.  
  128.  //printf("ERROR Packet Send\n\r");
  129.  
  130.                
  131.  // byte swap
  132.  sw.checksum = htonl(netbuffer->checksum);
  133.  sw.player = netbuffer->player;
  134.  sw.retransmitfrom = netbuffer->retransmitfrom;
  135.  sw.starttic = netbuffer->starttic;
  136.  sw.numtics = netbuffer->numtics;
  137.  for (c=0 ; c< netbuffer->numtics ; c++)
  138.  {
  139.   sw.cmds[c].forwardmove = netbuffer->cmds[c].forwardmove;
  140.   sw.cmds[c].sidemove = netbuffer->cmds[c].sidemove;
  141.   sw.cmds[c].angleturn = htons(netbuffer->cmds[c].angleturn);
  142.   sw.cmds[c].consistancy = htons(netbuffer->cmds[c].consistancy);
  143.   sw.cmds[c].chatchar = netbuffer->cmds[c].chatchar;
  144.   sw.cmds[c].buttons = netbuffer->cmds[c].buttons;
  145.  }
  146. // __libclog_printf("Sending packet %u to node %u\n",gametic,
  147. //     doomcom->remotenode);
  148. // __asm__ __volatile__(
  149. //     "int $0x40"
  150. //     :"=a"(c)
  151. //     :"0"(53),"b"(4),"c"(sendsocket[doomcom->remotenode]),
  152. //      "d"(doomcom->datalength),"S"((long)&sw));
  153. // if(c==-1)
  154. // {
  155. //  __libclog_printf("Unable to send packet to remote node\n");
  156. // }
  157. }
  158.  
  159. //
  160. // PacketGet
  161. //
  162. void PacketGet (void)
  163. {
  164. }
  165.  
  166. int GetLocalAddress (void)
  167. {
  168.  int d0;
  169. // __asm__ __volatile__(
  170. //     "int $0x40"
  171. //     :"=a"(d0)
  172. //     :"0"(52),"b"(1));
  173.  return d0;
  174. }
  175.  
  176.  
  177. //
  178. // I_InitNetwork
  179. //
  180.  
  181. void I_InitNetwork (void)
  182. {
  183.     boolean             trueval = true;
  184.     int                 i;
  185.     int                 p;
  186.        
  187.     doomcom = malloc (sizeof (*doomcom) );
  188.     memset (doomcom, 0, sizeof(*doomcom) );
  189.    
  190.     // set up for network
  191.     i = M_CheckParm ("-dup");
  192.     if (i && i< myargc-1)
  193.     {
  194.         doomcom->ticdup = myargv[i+1][0]-'0';
  195.         if (doomcom->ticdup < 1)
  196.             doomcom->ticdup = 1;
  197.         if (doomcom->ticdup > 9)
  198.             doomcom->ticdup = 9;
  199.     }
  200.     else
  201.         doomcom-> ticdup = 1;
  202.        
  203.     if (M_CheckParm ("-extratic"))
  204.         doomcom-> extratics = 1;
  205.     else
  206.         doomcom-> extratics = 0;
  207.                
  208.     p = M_CheckParm ("-port");
  209.     if (p && p<myargc-1)
  210.     {
  211.         DOOMPORT = atoi (myargv[p+1]);
  212. //      __libclog_printf ("using alternate port %i\n",DOOMPORT);
  213.     }
  214.  
  215.     // parse network game options,
  216.     //  -net <consoleplayer> <host> <host> ...
  217.     i = M_CheckParm ("-net");
  218.  
  219.     if (!i)
  220.     {
  221.         // single player game
  222.         netgame = false;
  223.         doomcom->id = DOOMCOM_ID;
  224.         doomcom->numplayers = doomcom->numnodes = 1;
  225.         doomcom->deathmatch = false;
  226.         doomcom->consoleplayer = 0;
  227.         return;
  228.     }
  229.  
  230.     netsend = PacketSend;
  231.     netget = PacketGet;
  232.     netgame = true;
  233.  
  234.     // parse player number and host list
  235.     doomcom->consoleplayer = myargv[i+1][0]-'1';
  236.  
  237.     doomcom->numnodes = 1;      // this node for sure
  238.     doomcom->id = DOOMCOM_ID;
  239.     doomcom->numplayers = doomcom->numnodes;
  240.     sendsocket[0]=0;
  241.     for(i=1;i<MAXNETNODES;i++)
  242.     {
  243.      sendsocket[i]=-1;
  244.     }
  245.     insocket=CreateInputUDPsocket();
  246.  //   __libclog_printf("DOOM: Input UDP socket is %d\n",insocket);
  247. }
  248.  
  249. void I_NetCmd (void)
  250. {
  251.  
  252.  
  253.     //printf("ERROR NetCmd");
  254.  
  255.  
  256.     if (doomcom->command == CMD_SEND)
  257.     {
  258. //      netsend ();
  259.     }
  260.     else if (doomcom->command == CMD_GET)
  261.     {
  262. //      netget ();
  263.     }
  264.     else
  265.         I_Error ("Bad net cmd: %i\n",doomcom->command);
  266. }
  267.