/*
 * Copyright 1988, 1989, 1990, 1991 Massachusetts Institute of Technology
 */
#include "structs.h"
#include "extens.h"

extdeal(msgsock, hostcommand, clinum)
     int msgsock, clinum;
     Galatea_packet *hostcommand;
{
  int i;
  
#ifdef SEAMLESS
  /* This is for backward compatibility with old clients */
  if (hostcommand->parm[0] > 0 && hostcommand->parm[0] < G_MINEXT) {
    int cc;
    switch (hostcommand->parm[0]) {
    case G_Download:
      cc = DoDownload(msgsock, &hostcommand, i);
      break;
    case G_PlayList:
      cc = DoPlayList(msgsock, &hostcommand, i);
      break;
    case G_FreeList:
      cc = DoFreeList(msgsock, &hostcommand, i);
      break;
    default:
      cc = -1;
      break;
    }
    return (cc);
  }
#endif /* SEAMLESS */
  i = hostcommand->parm[0] - G_MINEXT;
  if (i < 0 || i > NUM_EXTENS) return -1;
  if (exten_tbl[i].dofuncs == NULL) return -1;
  return(exten_tbl[i].dofuncs(msgsock, hostcommand, clinum));
}

extctrl(cmd, data)
     int cmd;
     caddr_t data;
{
  int i;
  for ( i = 0; i < NUM_EXTENS; i ++)
    if (exten_tbl[i].ctrlfuncs != NULL)
      exten_tbl[i].ctrlfuncs(cmd, data);
}

extnumexts()
{
  return NUM_EXTENS;
}

char *extname(i)
     int i;
{
  if (i < 0 || i > NUM_EXTENS) return (NULL);
  return (exten_tbl[i].the_name);
}
