Exemplo n.º 1
0
void* InterfaceMainLoop(void* arg)
{
   char *line = (char*) malloc(200);
   size_t size;
   //char buf[200];

   while (strcmp(line,"quit") != 0)
   {
      printf("blakadm> ");
      if (getline(&line, &size, stdin) != -1)
      {
      
         EnterServerLock();

         // TODO: in windows this uses a set char array of size 200, no bounds checking
         // is being done here yet
         //TryAdminCommand(console_session_id,buf);
         TryAdminCommand(console_session_id,line);

         LeaveServerLock();

      }
   }

   free(line);
   MessagePost(main_thread_id,WM_QUIT,0,0);
}
Exemplo n.º 2
0
long CALLBACK InterfaceAdminInputProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
{
	char buf[200];
	
	switch (message)
	{
	case WM_CHAR :
		if (wParam == '\r')
		{
			if (InMainLoop() && !GetQuit())
			{
				/* make sure we've started already, so that session id is valid */
				Edit_SetSel(hwnd,0,-1);
				Edit_GetText(hwnd,buf,sizeof buf);
				cprintf(console_session_id,"%s\n",buf);
				
				EnterServerLock();
				TryAdminCommand(console_session_id,buf);
				LeaveServerLock();
			}
			return 0;
		}
		if (wParam == '\t')
		{
			SetFocus(GetDlgItem(HWND_ADMIN,IDC_ADMIN_RESPONSE));
			return 0;      
		}
		
		
	}
	return CallWindowProc(lpfnDefAdminInputProc,hwnd,message,wParam,lParam);
}
Exemplo n.º 3
0
void AdminInputChar(session_node *s,char ch)
{
   int len,session_id;

   if (ch != CR)
   {
      len = strlen(s->adm->command);
      if (len < MAX_ADMIN_COMMAND - 1)
      {
	 s->adm->command[len] = ch;
	 s->adm->command[len+1] = 0;
      }
      return;
   }

   /* they hit CR, so they've done a command */

   cprintf(s->session_id,"> %s\n",s->adm->command);
   session_id = s->session_id;
   
   if (!strnicmp(s->adm->command,"QUIT",4))
   {
      cprintf(s->session_id,"%c%c",27,'G'); /* this tells client to resynchronize */
      SetSessionState(s,STATE_RESYNC);

      return;
      
   }
   
   TryAdminCommand(s->session_id,s->adm->command);
   
   /* this next stuff is fuzzy--not sure how much is needed 7/27/95 */
   
   /* right here, s could be invalid if we got hung up.
      check with the saved id */
   s = GetSessionByID(session_id);
   if (s == NULL)
      return;
   if (s->state == STATE_ADMIN)
   {
      /* set string to zero because the rest of line parameters (R) go past
       * a zero from a strtok, and could have residue from previous commands.
       * Of course, only do this if we didn't change state.
       */
      
      s->adm->command[0] = 0;
      memset(s->adm->command,0,MAX_ADMIN_COMMAND);
   }
}
Exemplo n.º 4
0
void MaintenanceInputChar(session_node *s,char ch)
{
   int len,session_id;

   if (ch != CR)
   {
      len = strlen(s->mtn->command);
      if (len < MAX_ADMIN_COMMAND - 1)
      {
	 s->mtn->command[len] = ch;
	 s->mtn->command[len+1] = 0;
      }
      return;
   }

   /* they hit CR, so they've done a command */

   cprintf(s->session_id,"> %s\n",s->mtn->command);
   session_id = s->session_id;
   
   if (!strnicmp(s->mtn->command,"QUIT",4))
   {
      cprintf(s->session_id,"Bye\n");
      HangupSession(s);
      return;
      
   }
   
   TryAdminCommand(s->session_id,s->mtn->command);
   
   /* right here, s could be invalid if we got hung up.
      check with the saved id */
   s = GetSessionByID(session_id);
   if (s == NULL)
      return;

   if (s->state == STATE_MAINTENANCE)
   {
      /* set string to zero because the rest of line parameters (R) go past
       * a zero from a strtok, and could have residue from previous commands.
       * Of course, only do this if we didn't change state.
       */
      
      s->mtn->command[0] = 0;
      memset(s->mtn->command,0,MAX_ADMIN_COMMAND);
   }
}
Exemplo n.º 5
0
void GameDMCommand(session_node *s,int type,char *str)
{
   char buf[LEN_MAX_CLIENT_MSG + 200];
   int acctype;

   acctype = ACCOUNT_NORMAL;
   if (s && s->account)
      acctype = s->account->type;

//   dprintf("DM command %i by session %i account %i acctype %i; string is \"%s\".\n",
//      type, s->session_id, s->account->account_id, acctype, str);

   switch (type)
   {
   case DM_CMD_GO_ROOM :
      if (0 != atoi(str))
      {
	 //ASSERT(0 != ACCOUNT_ADMIN);
	 //ASSERT(0 != ACCOUNT_DM);
	 if (ConfigInt(RIGHTS_GOROOMBYNUM) == 0)
	 {
	    dprintf("DM Command GOROOM (by number) disabled.");
	    break;
	 }
	 if (ConfigInt(RIGHTS_GOROOMBYNUM) == ACCOUNT_ADMIN && acctype == ACCOUNT_DM)
	 {
	    dprintf("DM Command GOROOM (by number) disabled for DMs; must be Admin.");
	    break;
	 }
      }
      if (ConfigInt(RIGHTS_GOROOM) == 0)
      {
	 dprintf("DM Command GOROOM disabled.");
	 break;
      }
      if (ConfigInt(RIGHTS_GOROOM) == ACCOUNT_ADMIN && acctype == ACCOUNT_DM)
      {
	 dprintf("DM Command GOROOM disabled for DMs; must be Admin.");
	 break;
      }
      sprintf(buf,"send object %i teleportto rid int %s",s->game->object_id,str);
      SendSessionAdminText(s->session_id,"~B> %s\n",buf); /* echo it to 'em */
      TryAdminCommand(s->session_id,buf); 
      break;

   case DM_CMD_GO_PLAYER :
      if (ConfigInt(RIGHTS_GOPLAYER) == 0)
	 break;
      if (ConfigInt(RIGHTS_GOPLAYER) == ACCOUNT_ADMIN && acctype == ACCOUNT_DM)
	 break;
      sprintf(buf,"send object %i admingotoobject what object %s",s->game->object_id,str);
      SendSessionAdminText(s->session_id,"~B> %s\n",buf); /* echo it to 'em */
      TryAdminCommand(s->session_id,buf); 
      break;

   case DM_CMD_GET_PLAYER :
      if (ConfigInt(RIGHTS_GETPLAYER) == 0)
	 break;
      if (ConfigInt(RIGHTS_GETPLAYER) == ACCOUNT_ADMIN && acctype == ACCOUNT_DM)
	 break;
      sprintf(buf,"send object %s admingotoobject what object %i",str,s->game->object_id);
      SendSessionAdminText(s->session_id,"~B> %s\n",buf); /* echo it to 'em */
      TryAdminCommand(s->session_id,buf); 
      break;

   default :
     eprintf("GameDMCommand got invalid DM command type %i\n",type);
     break;
      
   }
}
Exemplo n.º 6
0
void GameProtocolParse(session_node *s,client_msg *msg)
{
   user_node *u;
   int object_id;
   char *ptr;

   char password[MAX_LOGIN_PASSWORD+1],new_password[MAX_LOGIN_PASSWORD+1];
   int len,index;

   char admin_cmd[500];
   int admin_len;
   int dm_type;

   GameMessageCount((unsigned char)msg->data[0]);

   switch ((unsigned char)msg->data[0])
   {
   case BP_REQ_QUIT :
      GameClientExit(s);
      SetSessionState(s,STATE_SYNCHED);
      break;
      
   case BP_RESYNC :
      // dprintf("client said it had an error\n");
      GameSyncInit(s);
      GameSyncProcessSessionBuffer(s);
      break;

   case BP_PING :
      GameEchoPing(s);
      break;

   case BP_AD_SELECTED :
      /* they clicked on an ad; log it */
      switch (msg->data[1])
      {
      case 1:
	 ptr = LockConfigStr(ADVERTISE_URL1);
	 lprintf("GameProtocolParse found account %i visited ad 1, %s\n",s->account->account_id,
		 ptr);
	 UnlockConfigStr();
	 break;
      case 2:
	 ptr = LockConfigStr(ADVERTISE_URL2);
	 lprintf("GameProtocolParse found account %i visited ad 2, %s\n",s->account->account_id,
		 ptr);
	 UnlockConfigStr();
	 break;
      default :
	 eprintf("GameProtocolParse found account %i visited unknown ad %i\n",
		 s->account->account_id,msg->data[1]);
      }
      break;
         
   case BP_USE_CHARACTER :
      if (s->game->object_id == INVALID_OBJECT)
      {
	 object_id = *((int *)(msg->data+1));
	 u = GetUserByObjectID(object_id);
	 if (u != NULL && u->account_id == s->account->account_id)
	    GameStartUser(s,u);
	 else
	    eprintf("GameProtocolParse can't find user for obj %i in use char!!!\n",
		    object_id);
	 InterfaceUpdateSession(s);
      }
      break;

   case BP_REQ_ADMIN :
      if (s->account->type != ACCOUNT_ADMIN)
      {
	 eprintf("GameProtocolParse got admin command from non admin account %i\n",
		 s->account->account_id);
	 break;
      }
      admin_len = (int) * ((short *)(msg->data + 1));
      if (admin_len > msg->len - 3)
	 return;
      if (admin_len > sizeof(admin_cmd)-2)
	 return;
      memcpy(admin_cmd,&msg->data[3],admin_len);
      admin_cmd[admin_len] = 0;
      SendSessionAdminText(s->session_id,"> %s\n",admin_cmd); /* echo it to 'em */
      TryAdminCommand(s->session_id,admin_cmd);
      break;

   case BP_REQ_DM :
      if (s->account->type != ACCOUNT_ADMIN && s->account->type != ACCOUNT_DM)
      {
	 eprintf("GameProtocolParse got DM command from non admin or DM account %i\n",
		 s->account->account_id);
	 break;
      }
      dm_type = msg->data[1];

      admin_len = (int) * ((short *)(msg->data + 2));
      if (admin_len > msg->len - 4)
	 return;
      if (admin_len > sizeof(admin_cmd)-2)
	 return;
      memcpy(admin_cmd,&msg->data[4],admin_len);
      admin_cmd[admin_len] = 0;
      GameDMCommand(s,dm_type,admin_cmd);
      break;

   case BP_SEND_CHARACTERS :
      GameTryGetUser(s);
      break;

   case BP_CHANGE_PASSWORD :
      index = 1;
      len = *(short *)(msg->data+index);
      if (index + 2 + len > msg->len) /* 2 = length word len */
	 break;
      if (len-1 > sizeof(password))
	 break;
      memcpy(password,msg->data+index+2,len);
      password[len] = 0; /* null terminate string */
      index += 2 + len;
      
      len = *(short *)(msg->data+index);
      if (index + 2 + len > msg->len)
	 break;
      if (len-1 > sizeof(new_password))
	 break;
      memcpy(new_password,msg->data+index+2,len);
      new_password[len] = 0; /* null terminate string */
      index += 2 + len;

      if (strcmp(s->account->password,password))
      {
	 AddByteToPacket(BP_PASSWORD_NOT_OK);
	 SendPacket(s->session_id);
	 break;
      }

      SetAccountPasswordAlreadyEncrypted(s->account,new_password);
      AddByteToPacket(BP_PASSWORD_OK);
      SendPacket(s->session_id);

      break;

   default :
      ClientToBlakodUser(s,msg->len,msg->data);
      
      break;
   }
}