<?php
// This file is used by ManiaDrive to upload
// scores to CQFD Corp website.

// Webservice WSDL URL
$url = "http://maniadrive.raydium.org/ecrire/tools/maniadrive/WSManiaDrive.php?wsdl";

// set the proxy according to the configuration database
$proxy = '';
raydium_parser_db_get("Generic-Proxy", &$proxy, "");
$proxy=parse_url($proxy);

try {
  // Create the client instance
  $client = new SoapClient($url, array('proxy_host' => $proxy["host"],
                                       'proxy_port' => (int) $proxy["port"],
                                       )
                           );
  // Call the SOAP method
  $result = $client->ScoreAddNew($name, $track, $score, $version);

  // Display the result
  $result++;
  raydium_log('Debug : Level=' . $result);
  $position= (int) $result;
}
catch (SoapFault $fault) {
  raydium_log("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})");
  $position = 0;
}

?>
(my)glut: ERROR: Can't get window DC" ) ;
    exit ( 1 ) ;
  }

//  wglGetExtensionsStringARBtype *wglGetExtensionsStringARB = (wglGetExtensionsStringARBtype *)wglGetProcAddress ( "wglGetExtensionsStringARB" ) ;
//  const char *extensionsString = wglGetExtensionsStringARB ( currDC ) ;

//  printf ( "%s %x %s\n", glGetString ( GL_EXTENSIONS ), wglGetExtensionsStringARB, extensionsString ) ;

//  if (!GLExtensionExists("WGL_ARB_multisample "))
//    return suggestedFormat;


  pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR);
  pfd.nVersion=1;
  pfd.dwFlags=PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  pfd.iPixelType=PFD_TYPE_RGBA;
  pfd.cColorBits=24;
  pfd.cRedBits=0;
  pfd.cRedShift=0;
  pfd.cGreenBits=0;
  pfd.cGreenShift=0;
  pfd.cBlueBits=0;
  pfd.cBlueShift=0;
  pfd.cAlphaBits=0;
  pfd.cAlphaShift=0;
  pfd.cAccumBits=0;
  pfd.cAccumRedBits=0;
  pfd.cAccumGreenBits=0;
  pfd.cAccumBlueBits=0;
  pfd.cAccumAlphaBits=0;
  pfd.cDepthBits=32;
  pfd.cStencilBits=1;
  pfd.cAuxBuffers=0;
  pfd.iLayerType=PFD_MAIN_PLANE;
  pfd.bReserved=0;
  pfd.dwLayerMask=0;
  pfd.dwVisibleMask=0;
  pfd.dwDamageMask=0;


  /* Get best available match of pixel format for DC */
  iPixelFormat = ChoosePixelFormat ( currDC, &pfd ) ;
  if ( iPixelFormat == 0 )
  {
    raydium_log("(my)glut: ERROR: Can't get OpenGL pixel format" ) ;
    exit ( 1 ) ;
  }

  /* Set the pixel format of the DC */
  if ( !SetPixelFormat( currDC, iPixelFormat, &pfd ) )
  {
    raydium_log("(my)glut: ERROR: Can't set OpenGL pixel format" ) ;
    exit ( 1 ) ;
  }

  /* Show the window and paint its contents */
  ShowWindow ( currWnd, SW_SHOW ) ;
  UpdateWindow ( currWnd ) ;

  /* Create openGL context and make it current */
  currGLRC = wglCreateContext ( currDC ) ;
  if ( !currGLRC )
  {
    raydium_log("(my)glut: ERROR: Unable to open a suitable window");
    exit ( 1 ) ;
  }
  if ( !wglMakeCurrent ( currDC, currGLRC ) )
  {
    raydium_log("(my)glut: ERROR: Unable to open a suitable window");
    exit ( 1 ) ;
  }


  glClear ( GL_COLOR_BUFFER_BIT ) ;
  glutSwapBuffers () ;
  glClear ( GL_COLOR_BUFFER_BIT ) ;
  glutSwapBuffers () ;

//  if (glutReshapeFuncCB)
//      glutReshapeFuncCB(w, h);
  DescribePixelFormat(currDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
  raydium_log("Found %ix%i with %i bpp color and %i bits zbuffer (stencil is %i)",w,h,pfd.cColorBits,pfd.cDepthBits,pfd.cStencilBits);
}



LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
  static int key = -1 ;
  static int updown = GLUT_UP ;
  static int old_key = -1 ;  // We need this because "key" changes case
  int button = -1 ;
  static int mb = 0 ;
  static int lastx = 0 ;
  static int lasty = 0 ;
  BYTE state[256];
  WORD code[2];
  signed char b;
  signed char special=0;
  signed char repeating=0;
  int size[2];

  switch (uMsg)
  {
    case WM_LBUTTONDOWN:
    case WM_MBUTTONDOWN:
    case WM_RBUTTONDOWN:
      updown = GLUT_DOWN ;
      if      ( uMsg == WM_LBUTTONDOWN ) { button = GLUT_LEFT_BUTTON   ; mb |= 1 ; }
      else if ( uMsg == WM_MBUTTONDOWN ) { button = GLUT_MIDDLE_BUTTON ; mb |= 2 ; }
      else                               { button = GLUT_RIGHT_BUTTON  ; mb |= 4 ; }
      SetCapture ( hWnd ) ;
      lastx = (LOWORD( lParam ) ) ;
      lasty = (HIWORD( lParam ) ) ;
      if ( button != -1 && glutMouseFuncCB )
        (*glutMouseFuncCB) ( button, updown, lastx, lasty ) ;
      break;

    case WM_LBUTTONUP:
    case WM_MBUTTONUP:
    case WM_RBUTTONUP:
      updown = GLUT_UP ;
      if      ( uMsg == WM_LBUTTONUP ) { button = GLUT_LEFT_BUTTON   ; mb &= ~1 ; }
      else if ( uMsg == WM_MBUTTONUP ) { button = GLUT_MIDDLE_BUTTON ; mb &= ~2 ; }
      else                             { button = GLUT_RIGHT_BUTTON  ; mb &= ~4 ; }
      if ( mb == 0 ) ReleaseCapture () ;
      lastx = (LOWORD( lParam ) ) ;
      lasty = (HIWORD( lParam ) ) ;
      if ( button != -1 && glutMouseFuncCB )
        (*glutMouseFuncCB) ( button, updown, lastx, lasty ) ;
      break;

    case WM_MOUSEMOVE:
      lastx = (LOWORD( lParam ) );
      lasty = (HIWORD( lParam ) );
      if ( glutPassiveMotionFuncCB )
        (*glutPassiveMotionFuncCB) ( lastx, lasty ) ;
      break;

    case WM_MOUSEWHEEL:
    if ( ( short ) HIWORD( wParam ) > 0 )
    {
    if ( glutPassiveMotionFuncCB )
        (*glutMouseFuncCB) ( 3, GLUT_DOWN, lastx, lasty ) ;
    if ( glutPassiveMotionFuncCB )
        (*glutMouseFuncCB) ( 3, GLUT_UP, lastx, lasty ) ;
    }
    else
    {
    if ( glutPassiveMotionFuncCB )
        (*glutMouseFuncCB) ( 4, GLUT_DOWN, lastx, lasty ) ;
    if ( glutPassiveMotionFuncCB )
        (*glutMouseFuncCB) ( 4, GLUT_UP, lastx, lasty ) ;
    }

    case WM_KEYDOWN:
      // If the key is already down, we are on auto-repeat.  Break if the autorepeat is disabled.
      if ( ( updown == GLUT_DOWN ) && ( (int)wParam == old_key ) )
      {
/*        if ( autoRepeat )
        {*/
          // Disable CTRL, SHIFT, CapsLock keys from making a callback
          if ( ( key == VK_CONTROL ) || ( key == VK_SHIFT ) || ( key == VK_CAPITAL ) )
            break ;

/*          if ( key != -1 && kbCB )  // Autorepeat enabled, call the callback with an "up" setting
            (*kbCB) ( key, PW_UP, lastx, lasty ) ;
        }
        else*/
          repeating=1;
        }

      updown = GLUT_DOWN ;
      old_key = wParam ;
      // FALLTHROUGH
    case WM_KEYUP:
      if ( uMsg == WM_KEYUP ) updown = GLUT_UP ;
      key = wParam ;

      // Disable CTRL, SHIFT, CapsLock keys from making a callback
      if ( ( key == VK_CONTROL ) || ( key == VK_SHIFT ) || ( key == VK_CAPITAL ) )
        break ;

      switch ( key )
      {
        case VK_F1:     key = GLUT_KEY_F1;   special=1;     break;
        case VK_F2:     key = GLUT_KEY_F2;   special=1;     break;
        case VK_F3:     key = GLUT_KEY_F3;   special=1;     break;
        case VK_F4:     key = GLUT_KEY_F4;   special=1;     break;
        case VK_F5:     key = GLUT_KEY_F5;   special=1;     break;
        case VK_F6:     key = GLUT_KEY_F6;   special=1;     break;
        case VK_F7:     key = GLUT_KEY_F7;   special=1;     break;
        case VK_F8:     key = GLUT_KEY_F8;   special=1;     break;
        case VK_F9:     key = GLUT_KEY_F9;   special=1;     break;
        case VK_F10:    key = GLUT_KEY_F10;  special=1;     break;
        case VK_F11:    key = GLUT_KEY_F11;  special=1;     break;
        case VK_F12:    key = GLUT_KEY_F12;  special=1;     break;

        case VK_LEFT:   key = GLUT_KEY_LEFT;   special=1;   break;
        case VK_RIGHT:  key = GLUT_KEY_RIGHT;  special=1;   break;
        case VK_UP:     key = GLUT_KEY_UP;     special=1;   break;
        case VK_DOWN:   key = GLUT_KEY_DOWN;   special=1;   break;

        case VK_PRIOR:  key = GLUT_KEY_PAGE_UP;   special=1; break;
        case VK_NEXT:   key = GLUT_KEY_PAGE_DOWN; special=1; break;
        case VK_HOME:   key = GLUT_KEY_HOME;      special=1; break;
        case VK_END:    key = GLUT_KEY_END;       special=1; break;
        case VK_INSERT: key = GLUT_KEY_INSERT;    special=1; break;

        default: // don't do this for WinCE
            b = GetKeyboardState( state );
            if(b){
                code [ 0 ] = 0; // WK: I need to do this, or on my Win2k box, the upper bits remain unchanged.
                if( ToAscii( key, 0, state, code, 0 ) == 1 )
                    if((0xFF00 & code[0]) == 0) // setting a high bit in key causes crashes later on (out of range array access)
                        key=code[ 0 ];
            }
      }
      if ( key != -1)
        {

            // special down
            if(special && updown==GLUT_DOWN && glutSpecialFuncCB && !repeating)
                glutSpecialFuncCB(key,lastx,lasty);

            // special up
            if(special && updown==GLUT_UP && glutSpecialUpFuncCB && !repeating)
                glutSpecialUpFuncCB(key,lastx,lasty);

        // normal
            if(!special && updown==GLUT_DOWN && glutKeyboardFuncCB)
                glutKeyboardFuncCB(key,lastx,lasty);


        /*if(!special && repeating && glutKeyboardFuncCB)
        glutKeyboardFuncCB(key,lastx,lasty);*/

        //(*kbCB) ( key, updown, lastx, lasty ) ;
        }
      break;

    case WM_SIZE:
      size[0] = LOWORD(lParam) ;
      size[1] = HIWORD(lParam) ;
      _glutWindowSize[0]=size[0];
      _glutWindowSize[1]=size[1];
      _glutWindowInverseRatio=0;
      if (glutReshapeFuncCB)
            glutReshapeFuncCB(size[0], size[1]);
      break;

    case WM_CLOSE:
      exit(0);
      break;

    default:
      return ( DefWindowProc ( hWnd, uMsg, wParam, lParam ) ) ;
  }

  return 0;
}