Ejemplo n.º 1
0
void InterfaceLogic::mainMenuUpdate()
{
  switch (mainMenu.update())
  {
    case MenuLogic::resNewGame:
      closeInterface(resNewGame);
      break;
    case MenuLogic::resSettings:
      goNextState(stSettings);
      break;
    case MenuLogic::resLeaderboard:
      goNextState(stLeaderboard);
      break;
    case MenuLogic::resQuitConfirmation:
      goNextState(stQuitConfirmation);
      break;
    case MenuLogic::resNone:
      break;
    default:
      assert(0);
      break;
  }

  if (mainMenu.state == MenuLogic::stHiding && mainMenu.result == MenuLogic::resNewGame)
    menuShadeProgress = mainMenu.transitionProgress;
  else
    menuShadeProgress = 1.0f;
}
Ejemplo n.º 2
0
void InterfaceLogic::restartConfirmationUpdate()
{
  switch (restartConfirmationMenu.update())
  {
    case MenuLogic::resBack:
      goPreviousState();
      break;
    case MenuLogic::resRestart:
      closeInterface(resNewGame);
      break;
    case resNone:
      break;
    default:
      assert(0);
      break;
  }

  if (restartConfirmationMenu.state == MenuLogic::stHiding &&
      restartConfirmationMenu.result == MenuLogic::resRestart)
  {
    menuShadeProgress = restartConfirmationMenu.transitionProgress;
  }
  else
    menuShadeProgress = 1.0f;
}
Ejemplo n.º 3
0
void InterfaceLogic::inGameMenuUpdate()
{
  switch (inGameMenu.update())
  {
    case MenuLogic::resBack:
    case MenuLogic::resContinue:
      closeInterface(resContinueGame);
      break;
    case MenuLogic::resRestartConfirmation:
      goNextState(stRestartConfirmation);
      break;
    case MenuLogic::resSettings:
      goNextState(stSettings);
      break;
    case MenuLogic::resExitToMainConfirmation:
      goNextState(stExitToMainConfirmation);
      break;
    case resNone:
      break;
    default:
      assert(0);
      break;
  }

  if ((inGameMenu.state == MenuLogic::stShowing && prevState == stHidden) ||
      (inGameMenu.state == MenuLogic::stHiding && inGameMenu.result == MenuLogic::resContinue))
  {
    menuShadeProgress = inGameMenu.transitionProgress;
  }
  else
    menuShadeProgress = 1.0f;
}
Ejemplo n.º 4
0
static int processBytesRead(Interface * interface, int bytesRead) {
	int ret = 0;

	while(bytesRead > 0) {
		interface->bufferLength++;
		bytesRead--;
		if(interface->buffer[interface->bufferLength-1]=='\n') {
			interface->buffer[interface->bufferLength-1] = '\0';
			ret = proccessLineOfInput(interface);
			interface->bufferPos = interface->bufferLength;
		}
		if(interface->bufferLength==INTERFACE_MAX_BUFFER_LENGTH)
		{
			if(interface->bufferPos == 0) {
				ERROR("interface %i: buffer overflow\n",
						interface->num);
				closeInterface(interface);
				return 1;
			}
			interface->bufferLength-= interface->bufferPos;
			memmove(interface->buffer, 
					interface->buffer+interface->bufferPos,
					interface->bufferLength);
			interface->bufferPos = 0;
		}
 	}
 
	return ret;
}
Ejemplo n.º 5
0
void closeInterfaceWithFD(int fd) {
	int i;

	for(i=0;i<interface_max_connections;i++) {
		if(interfaces[i].fd==fd) {
			closeInterface(&(interfaces[i]));
		}
	}
}
Ejemplo n.º 6
0
void closeOldInterfaces() {
	int i;

	for(i=0;i<interface_max_connections;i++) {
		if(interfaces[i].open && (interfaces[i].expired || (time(NULL)-interfaces[i].lastTime>interface_timeout))) {
			DEBUG("interface %i: timeout\n",i);
			closeInterface(&(interfaces[i]));
		}
	}
}
Ejemplo n.º 7
0
void closeAllInterfaces() {
	int i;

	fflush(NULL);

	for(i=0;i<interface_max_connections;i++) {
		if(interfaces[i].open) {
			closeInterface(&(interfaces[i]));
		}
	}
}
Ejemplo n.º 8
0
int interfaceReadInput(Interface * interface) {
	int bytesRead;
	
	bytesRead = read(interface->fd, 
			interface->buffer+interface->bufferLength, 
			INTERFACE_MAX_BUFFER_LENGTH-interface->bufferLength);
	
	if(bytesRead > 0) return processBytesRead(interface, bytesRead);
	else if(bytesRead == 0 || (bytesRead < 0 && errno != EINTR)) {
		closeInterface(interface);
	}
	else return 0;

	return 1;
}
Ejemplo n.º 9
0
void InterfaceLogic::quitConfirmationUpdate()
{
  switch (quitConfirmationMenu.update())
  {
    case MenuLogic::resBack:
      goPreviousState();
      break;
    case MenuLogic::resQuit:
      closeInterface(resCloseApp);
      break;
    case resNone:
      break;
    default:
      assert(0);
      break;
  }
}
Ejemplo n.º 10
0
void closeNextErroredInterface() {
	fd_set fds;
	struct timeval tv;
	int i;

	tv.tv_sec = 0;
	tv.tv_usec = 0;

	for(i=0;i<interface_max_connections;i++) {
		if(interfaces[i].open) {
			FD_ZERO(&fds);
			FD_SET(interfaces[i].fd,&fds);
			if(select(FD_SETSIZE,&fds,NULL,NULL,&tv)<0) {
				closeInterface(&interfaces[i]);
				return;
			}
		}
	}
}
Ejemplo n.º 11
0
	virtual ~WindowsPCAPNetworkInterface() {
		closeInterface( handle );
		if( handle != NULL ) freePacketHandle( handle );
	}
Ejemplo n.º 12
0
/*
Destructor for XIO Object.
*/
XIO::~XIO() {
    closeInterface();
}
Ejemplo n.º 13
0
static int proccessLineOfInput(Interface * interface) {
	int ret = 1;
	char * line = interface->buffer+interface->bufferPos;

	if(interface->bufferLength - interface->bufferPos > 1) {
		if(interface->buffer[interface->bufferLength-2] == '\r') {
			interface->buffer[interface->bufferLength-2] = '\0';
		}
	}

	if(interface->commandList) {
		if(strcmp(line, INTERFACE_LIST_MODE_END)==0) {
			DEBUG("interface %i: process command "
					"list\n",interface->num);
			ret = proccessListOfCommands(
					interface->fp,
					&(interface->permission),
					&(interface->expired),
                                        interface->commandListOK,
					interface->commandList);
			DEBUG("interface %i: process command "
					"list returned %i\n",
					interface->num,
					ret);
			if(ret==0) commandSuccess(interface->fp);
			else if(ret==COMMAND_RETURN_CLOSE || interface->expired)
			{
						
				closeInterface(interface);
			}

			printInterfaceOutBuffer(interface);
			freeList(interface->commandList);
			interface->commandList = NULL;
		}
		else {
			interface->commandListSize+= sizeof(ListNode);
			interface->commandListSize+= strlen(line)+1;
			if(interface->commandListSize > 
					interface_max_command_list_size)
			{
				ERROR("interface %i: command "
						"list size (%zu) is "
						"larger than the max "
						"(%zu)\n",
						interface->num,
						interface->
						commandListSize,
						interface_max_command_list_size)
					;
				closeInterface(interface);
			}
			else {
				insertInListWithoutKey(interface->commandList,
							strdup(line));
			}
		}
	}
	else {
		if(strcmp(line, INTERFACE_LIST_MODE_BEGIN) == 0) {
			interface->commandList = makeList(free, 1);
			interface->commandListSize = sizeof(List);
                        interface->commandListOK = 0;
			ret = 1;
		}
		else if(strcmp(line, INTERFACE_LIST_OK_MODE_BEGIN) == 0) {
			interface->commandList = makeList(free, 1);
			interface->commandListSize = sizeof(List);
                        interface->commandListOK = 1;
			ret = 1;
		}
		else {
			DEBUG("interface %i: process command \"%s\"\n",
					interface->num, line);
			ret = processCommand(interface->fp,
						&(interface->permission),
						line);
			DEBUG("interface %i: command returned %i\n",
						interface->num, ret);
			if(ret==0) commandSuccess(interface->fp);
			else if(ret==COMMAND_RETURN_CLOSE || interface->expired)
			{
				closeInterface(interface);
			}
			printInterfaceOutBuffer(interface);
		}
	}

	return ret;
}