コード例 #1
0
ファイル: main.cpp プロジェクト: tocchan/guildhall_sd6
//-------------------------------------------------------------------------------------------------------
int main( int argc, char const **argv )
{
   if (!NetSystemInit()) {
      printf( "Failed to initialize net system.\n" );
      _getch();
      return false;
   }

   // List Addresses
   char const *hostname = AllocLocalHostName();
   ListAddressesForHost( hostname, gHostPort );
   FreeLocalHostName(hostname);

   // Host/Client Logic
   if ((argc <= 1) || (_strcmpi( argv[1], "sock" ) == 0)) {
      printf( "Hosting...\n" );
      NetworkHost( gHostPort ); 
   } else if (argc > 2) {
      char const *addr = argv[1];
      char const *msg = argv[2];
      printf( "Sending message \"%s\" to [%s]\n", msg, addr );
      NetworkClient( addr, gHostPort, msg );
   } else {
      char const *msg = argv[1];
      printf( "Broadcast message \"%s\".\n", msg );
      NetworkBroadcast( msg );
   }

   NetSystemDeinit();

   printf( "Press any key to continue...\n" );
   _getch();
   return 0;
}
コード例 #2
0
ファイル: game_newgame.cpp プロジェクト: asimonov-im/fheroes2
Game::menu_t Game::NewNetwork(void)
{
    Settings & conf = Settings::Get();
    conf.SetGameType(conf.GameType() | Game::TYPE_NETWORK);

    // cursor
    Cursor & cursor = Cursor::Get();
    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    Display & display = Display::Get();
    //Settings & conf = Settings::Get();

    // image background
    const Sprite &back = AGG::GetICN(ICN::HEROES, 0);
    const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2);
    back.Blit(top);

    const Sprite &panel = AGG::GetICN(ICN::REDBACK, 0);
    panel.Blit(top.x + 405, top.y + 5);

    LocalEvent & le = LocalEvent::Get();

    Button buttonHost(top.x + 455, top.y + 45, ICN::BTNNET, 0, 1);
    Button buttonGuest(top.x + 455, top.y + 110, ICN::BTNNET, 2, 3);
    Button buttonCancelGame(top.x + 455, top.y + 375, ICN::BTNMP, 8, 9);

    buttonHost.Draw();
    buttonGuest.Draw();
    buttonCancelGame.Draw();

    cursor.Show();
    display.Flip();

    // newgame loop
    while(le.HandleEvents())
    {
	le.MousePressLeft(buttonHost) ? buttonHost.PressDraw() : buttonHost.ReleaseDraw();
	le.MousePressLeft(buttonGuest) ? buttonGuest.PressDraw() : buttonGuest.ReleaseDraw();
	le.MousePressLeft(buttonCancelGame) ? buttonCancelGame.PressDraw() : buttonCancelGame.ReleaseDraw();

	if(le.MouseClickLeft(buttonHost) || HotKeyPress(EVENT_BUTTON_HOST)) return NetworkHost();
	if(le.MouseClickLeft(buttonGuest) || HotKeyPress(EVENT_BUTTON_GUEST)) return NetworkGuest();
	if(HotKeyPress(EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancelGame)) return MAINMENU;

        // right info
	if(le.MousePressRight(buttonHost)) Dialog::Message(_("Host"), _("The host sets up the game options. There can only be one host per network game."), Font::BIG);
	if(le.MousePressRight(buttonGuest)) Dialog::Message(_("Guest"), _("The guest waits for the host to set up the game, then is automatically added in. There can be multiple guests for TCP/IP games."), Font::BIG);
	if(le.MousePressRight(buttonCancelGame)) Dialog::Message(_("Cancel"), _("Cancel back to the main menu."), Font::BIG);
    }

    return Game::MAINMENU;
}