⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wsckcomm.c

📁 MUD服务器程序
💻 C
📖 第 1 页 / 共 5 页
字号:
//    wcMercClass.hIcon         = LoadIcon(hInstance, SetUpData.szAppName);
    wcMercClass.hIcon         = 0;
    wcMercClass.lpszMenuName  = (LPSTR) NULL;
    wcMercClass.hbrBackground = GetStockObject(WHITE_BRUSH);
    wcMercClass.style         = CS_HREDRAW | CS_VREDRAW;
    wcMercClass.cbClsExtra    = 0;
    wcMercClass.cbWndExtra    = 0;

    // Register the class
    if (RegisterClass(&wcMercClass) == 0)
       {
       MessageBox(0, "Could not create Window", "@@@", MB_ICONHAND|MB_OK);
       exit(1);
       }

    hInst = hInstance;       // save for use by window procs

    // Create applications main window.
    hWndMain = CreateWindow(
                  "Merc22",
                  "Welcome to Merc22/Win32",
                    WS_BORDER |
                    WS_CAPTION |
                    WS_SYSMENU |
                    WS_MINIMIZEBOX,
                  10,
                  19,
                  256,
                  123,
                  NULL,
                  NULL,
                  hInstance,
                  NULL
                  );

    CreateDialog(hInst, MAKEINTRESOURCE(1), hWndMain, (DLGPROC) MercDlgProc);
    ShowWindow(hWndMain, cmdShow);
    UpdateWindow(hWndMain);
}

/*int SpinTheMessageLoop()
{
   MSG msg;
   if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
      {
      if (msg.message == WM_QUIT)
         return FALSE;

      if (!IsDialogMessage(hQryDlgBox, &msg))
         {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
         }
      }

   return TRUE;
}*/

WPARAM game_loop_win32(HINSTANCE hInstance, HINSTANCE hPrevInstance, int nCmdShow)
{
//    static DESCRIPTOR_DATA dcon;
    DESCRIPTOR_DATA *d;
    MSG   msg;
    DWORD dwTick = 0;
    int   fBackground;
	extern char * help_greeting;
//   HDC hDC;
    char szBuffer[128];

   extern int			nAllocString;
   extern int			sAllocString;
   extern int			nAllocPerm;
   extern int			sAllocPerm;
   static int nOldNString = -1;
   static int nOldSString = -1;
   static int nOldNPerm = -1;
   static int nOldSPerm = -1;

    /* Main loop */

//    // Go init this application.
//    InitMerc22(hInstance, nCmdShow);

    // Get and dispatch messages for this applicaton.
    fBackground = FALSE;
    for ( ;; )
        {
        // Always give Windows messages priority over Merc execution
        if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
            {
            if (msg.message == WM_QUIT)
               break;

            if (!IsDialogMessage(hQryDlgBox, &msg))
               {
               TranslateMessage(&msg);
               DispatchMessage(&msg);
               }
            }
       else if (!fBackground)
          {
          fBackground++;

    time( &current_time );

	/*
	 * Autonomous game motion.
	 * (Synchronize to a clock.
	 * Busy wait (blargh).)
	 */
    if (GetTickCount() - dwTick >= 1000 / PULSE_PER_SECOND)
       {
       dwTick = GetTickCount();
	/*
	 * Process input.
	 */
	for ( d = descriptor_list; d != NULL; d = d_next )
	   {
       // Give Windows a change to run other programs
//       if (!SpinTheMessageLoop())
//          goto merc_done;

	   d_next	= d->next;
	   d->fcommand	= FALSE;

	   if ( d->character != NULL )
	        d->character->timer = 0;

#if 0
       // Did the user break connection?
	   if ( !read_from_descriptor( d ) )
	     	{
		    if ( d->character != NULL )
			save_char_obj( d->character );
		    d->outtop	= 0;
		    close_socket( d );
		    continue;
		    }
#endif
	    if ( d->character != NULL && d->character->wait > 0 )
	        {
		    --d->character->wait;
		    continue;
	        }

	    read_from_buffer( d );
	    if ( d->incomm[0] != '\0' )
	    {
		d->fcommand	= TRUE;
		stop_idling( d->character );

		if ( d->connected == CON_PLAYING )
		    if ( d->showstr_point )
		        show_string( d, d->incomm );
		    else
		        interpret( d->character, d->incomm );
		else
		    nanny( d, d->incomm );

		d->incomm[0]	= '\0';
	    }
	   }

       update_handler( );

       // Update the screen
       if (nAllocString != nOldNString || sAllocString != nOldSString)
          {
          nOldNString = nAllocString;
          nOldSString = sAllocString;
          wsprintf( szBuffer, "Strings %5d strings of %7d bytes",
             nAllocString, sAllocString);
          SetDlgItemText(hQryDlgBox, 103, szBuffer);
          }

       if (nAllocPerm != nOldNPerm || sAllocPerm != nOldSPerm)
          {
          wsprintf( szBuffer, "Perms   %5d blocks  of %7d bytes",
       	    nAllocPerm, sAllocPerm );
          nOldNPerm = nAllocPerm;
          nOldSPerm = sAllocPerm;
          SetDlgItemText(hQryDlgBox, 104, szBuffer);
          }

       if (nPlayers != nOldPlayers)
          {
          wsprintf( szBuffer, "%d", nPlayers);
          nOldPlayers = nPlayers;
          SetDlgItemText(hQryDlgBox, 101, szBuffer);
          }
	/*
	 * Output.
	 */
	for ( d = descriptor_list; d != NULL; d = d_next )
	{
       // Give Windows a change to run other programs
//       if (!SpinTheMessageLoop())
//          goto merc_done;

	    d_next = d->next;

	    if ( ( d->fcommand || d->outtop > 0 ) )
	    {
		if ( !process_output( d, TRUE ) && WSAGetLastError() != WSAEWOULDBLOCK)
		{
		    if ( d->character != NULL )
			save_char_obj( d->character );
		    d->outtop	= 0;
		    close_socket( d );
		}
	    }
	}


#if 0
	now_time = last_time;
	for ( ; ; )
	{
	    int delta;

	    {
		if ( dcon.character != NULL )
		    dcon.character->timer = 0;
		if ( !read_from_descriptor( &dcon ) )
		{
		    if ( dcon.character != NULL )
			save_char_obj( d->character );
		    dcon.outtop	= 0;
		    close_socket( &dcon );
		}
#if defined(MSDOS)
		break;
#endif
	    }

	    gettimeofday( &now_time, NULL );
	    delta = ( now_time.tv_sec  - last_time.tv_sec  ) * 1000 * 1000
		  + ( now_time.tv_usec - last_time.tv_usec );
	    if ( delta >= 1000000 / PULSE_PER_SECOND )
		break;
	}
	last_time    = now_time;
	current_time = (time_t) last_time.tv_sec;
#endif
       }
   fBackground--;
          }
       }
merc_done:

    return(msg.wParam);
}

//int main( int argc, char **argv )
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpszCmdLine, int nCmdShow)
{
    extern char * help_greeting;
    struct timeval now_time;
    int port;

//#if defined(unix)
//    int control;
//#endif
#ifdef WIN32
   WORD wVersionRequested = MAKEWORD( 1, 1 );

   WSADATA wsaData;
   int err;
#endif

    /*
     * Memory debugging if needed.
     */
#if defined(MALLOC_DEBUG)
    malloc_debug( 2 );
#endif

    /*
     * Init time.
     */
    gettimeofday( &now_time, NULL );
    current_time = (time_t) now_time.tv_sec;
    strcpy( str_boot_time, ctime( &current_time ) );

#if 0
    /*
     * Reserve one channel for our use.
     */
    if ( ( fpReserve = fopen( NULL_FILE, "r" ) ) == NULL )
    {
	perror( NULL_FILE );
	return 1;
    }
#endif

#if 0 // @@@
    /*
     * Get the port number.
     */
    port = 1234;
    if ( lpszCmdLine[0] )
    {
	if ( !is_number( lpszCmdLine ) )
	{
//	    fprintf( stderr, "Usage: Merc22sv [port #]\n" );
       MessageBox(0, "Usage: Merc22sv [port #]", "Merc22", MB_ICONHAND|MB_OK);
	    return 1;
	}
#if 0
	else if ( ( port = atoi( lpszCmdLine ) ) <= 1024 )
	{
	    fprintf( stderr, "Port number must be above 1024.\n" );
	    return 1;
	}
#endif
    }
#else
    port = GetProfileInt("MercW32", "PortNum", 23); // %%%
#endif

#ifdef WIN32
   err = WSAStartup( wVersionRequested, &wsaData );
   if ( err != 0 ) {
      MessageBox(0, "No useable WINSOCK.DLL, not loading sockets", "Serv",
         MB_ICONHAND|MB_OK);

      return INVALID_SOCKET;
      }

   /* Confirm that the Windows Sockets DLL supports 1.1.*/
   /* Note that if the DLL supports versions greater    */
   /* than 1.1 in addition to 1.1, it will still return */
   /* 1.1 in wVersion since that is the version we      */
   /* requested.                                        */

   if ( LOBYTE( wsaData.wVersion ) != 1 ||
         HIBYTE( wsaData.wVersion ) != 1 ) {
      /* Tell the user that we couldn't find a useable */
      /* winsock.dll.                                  */
      WSACleanup( );
      MessageBox(0, "Windows sockets version not 1.1, not loading sockets", "Serv",
         MB_ICONHAND|MB_OK);

      return INVALID_SOCKET;
      }

   /* Make sure that the version requested is >= 1.1.   */
   /* The low byte is the major version and the high    */
   /* byte is the minor version.                        */

   if ( LOBYTE( wVersionRequested ) < 1 ||
        ( LOBYTE( wVersionRequested ) == 1 &&
          HIBYTE( wVersionRequested ) < 1 )) {
      MessageBox(0, "Windows sockets version not 1.1, not loading sockets", "Serv",
         MB_ICONHAND|MB_OK);

       return INVALID_SOCKET;
   }

   /* Since we only support 1.1, set both wVersion and  */
   /* wHighVersion to 1.1.                              */

//   wsaData.wVersion = MAKEWORD( 1, 1 );
//   wsaData.wHighVersion = MAKEWORD( 1, 1 );
#endif

    // Go init this application.
    fpStderr = fopen( STDERR_FILE, "a" );
    InitMerc22(hInstance, nCmdShow);

    // Load the areas
    log_string( "Loading areas" );
    UpdateWindow(hWndOutput);
    boot_db( );

    // Validate enough of zones loaded to run Merc
    if (help_greeting == 0)
       log_string( "Error: areas.lst did not include help.are.  Game will crash when players log in" );
#ifdef MERCW32
    if (get_obj_index(OBJ_VNUM_ERROR) == 0)
       {
       log_string( "Error: Object #4 missing (check limbo.are).  MercW32 needs object #4");
       log_string( "  to prevent crashes when players with invalid equipment log in.");
       log_string( "  check LIMBO.ARE");
       }
#endif
    if (get_obj_index(OBJ_VNUM_MONEY_ONE) == 0 || get_obj_index(OBJ_VNUM_MONEY_SOME) == 0)
       log_string( "Error: Money objects #2 #3 did not load.  Check LIMBO.ARE");
    if (get_obj_index(OBJ_VNUM_CORPSE_NPC) == 0 || get_obj_index(OBJ_VNUM_CORPSE_PC) == 0)
       log_string( "Error: Corpse templates did not load.  Check LIMBO.ARE");
    if (get_obj_index(OBJ_VNUM_SEVERED_HEAD) == 0 || get_obj_index(OBJ_VNUM_TORN_HEART) == 0 ||
        get_obj_index(OBJ_VNUM_SLICED_ARM) == 0 || get_obj_index(OBJ_VNUM_SLICED_LEG) == 0 ||
        get_obj_index(OBJ_VNUM_FINAL_TURD) == 0)
       log_string( "Error: Severed body parts did not load.  Check LIMBO.ARE");
    if (get_obj_index(OBJ_VNUM_MUSHROOM) == 0 || get_obj_index(OBJ_VNUM_LIGHT_BALL) == 0 ||
        get_obj_index(OBJ_VNUM_SPRING) == 0)
       log_string( "Error: Spell objects did not load.  Check LIMBO.ARE #20 #21 #22");
    if (get_obj_index(OBJ_VNUM_SCHOOL_MACE) == 0 || get_obj_index(OBJ_VNUM_SCHOOL_DAGGER) == 0 ||
        get_obj_index(OBJ_VNUM_SCHOOL_SWORD) == 0 || get_obj_index(OBJ_VNUM_SCHOOL_VEST) == 0 ||
        get_obj_index(OBJ_VNUM_SCHOOL_SHIELD) == 0 || get_obj_index(OBJ_VNUM_SCHOOL_BANNER) == 0)
       log_string( "Error: New player equipment did not load.  Check SCHOOL.ARE");
    if (get_room_index(ROOM_VNUM_LIMBO) == 0)
       log_string( "Error: The Void did not load.  Check LIMBO.ARE");
    if (get_room_index(ROOM_VNUM_CHAT) == 0)
       log_string( "Error:  Immortal chat-room did not load.  Check HITOWER.ARE");
    if (get_room_index(ROOM_VNUM_TEMPLE) == 0 || get_room_index(ROOM_VNUM_ALTAR) == 0)
       log_string( "Error: Midgaard temple and Alter necessary for game.  Check MIDGAARD.ARE");
    if (get_room_index(ROOM_VNUM_SCHOOL) == 0)
       log_string( "Error: New player initial room did not load.  Check SCHOOL.ARE" );

    // #define MOB_VNUM_CITYGUARD	   3060
    // #define MOB_VNUM_VAMPIRE	   3404
    // #define MOB_VNUM_WALKING_DEAD 20

    // Initialize sockets
    log_string( "Initializing sockets" );
    UpdateWindow(hWndOutput);
    control = init_socket( port );

    // Tell Winsock we are listening for accepted sockets
    WSAAsyncSelect(control, hQryDlgBox, WM_NET_ACCEPT, FD_ACCEPT);

    sprintf( log_buf, "Merc is ready to rock on port %d.", port );
    log_string( log_buf );
    game_loop_win32(hInstance, hPrev, nCmdShow);
    closesocket( control );

    /*
     * That's all, folks.
     */
    log_string( "Normal termination of game." );
    fclose(fpStderr);

#ifdef WIN32
    WSACleanup( );
#endif

    return 0;
}

// @@@ Orig junk

/*
 * The primary output interface for formatted output.
 */
void act( const char *format, CHAR_DATA *ch, const void *arg1,
	 const void *arg2, int type )
{
    static char * const he_she	[] = { "it",  "he",  "she" };
    static char * const him_her	[] = { "it",  "him", "her" };
    static char * const his_her	[] = { "its", "his", "her" };

    char buf[MAX_STRING_LENGTH];
    char fname[MAX_INPUT_LENGTH];
    CHAR_DATA *to;
    CHAR_DATA *vch = (CHAR_DATA *) arg2;
    OBJ_DATA *obj1 = (OBJ_DATA  *) arg1;
    OBJ_DATA *obj2 = (OBJ_DATA  *) arg2;
    const char *str;
    const char *i;
    char *point;

    /*
     * Discard null and zero-length messages.
     */
    if ( format == NULL || format[0] == '\0' )
	return;

    to = ch->in_room->people;
    if ( type == TO_VICT )
    {
	if ( vch == NULL )
	{
	    bug( "Act: null vch with TO_VICT.", 0 );
	    return;
	}
	to = vch->in_room->people;
    }
    
    for ( ; to != NULL; to = to->next_in_room )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -