/** * Invoked when any data arrives from the remote host * */ void DSocket::OnReceive(int errcode) { CString address; char hname[400],str[1000],mesg[500]; unsigned int port,retvalue; int n,len; RequestDlg rdlg(NULL); // Note : if no error has occured then RETVALUE contains // the COUNT of actual bytes received. // Control type if(type==TYPE_CONTROL) { retvalue=this->ReceiveFrom(data,length,address,port); if(retvalue==SOCKET_ERROR) return; // Get host name from the data. int i=0; for( i=0;i<data[1];i++) { hname[i]=data[i+2]; } hname[i]=0; strcpy(remotename,hname); strcpy(remoteaddress,(LPCTSTR)address); switch(data[0]) { // action : Remote user has sent the invitation for conference // reaction : accept/reject the invitation case MESG_CONNECT: // display the accept , reject dialog box rdlg.SetParameter(remotename,remoteaddress,pdlg); rdlg.DoModal(); return; // action : Remote user has disconnected // reaction : destroy the conference case MESG_DISCONNECT: ( (CVideoNetDlg*)pdlg)->DestroyConference(); sprintf(str,"User %s has disconnected",hname); AfxMessageBox(str); return; // action : Remote user has accepted the invitation // reaction : start the conference case MESG_ACCEPT: //AfxMessageBox("User has accepted the connection"); ( (CVideoNetDlg*)pdlg)->StartConference(); return; // action : Remote user has rejected the invitation // reaction : what to do...? case MESG_REJECT: sprintf(str,"User %s has rejected your invitation",hname); AfxMessageBox(str); return; } return; } if(type==TYPE_AUDIO) { retvalue=this->ReceiveFrom(adata,alength,address,port); if(retvalue==SOCKET_ERROR) return; // Play the audio ((CVideoNetDlg *)pdlg)->play->PostThreadMessage(WM_PLAYSOUND_PLAYBLOCK,retvalue,(LPARAM)adata); return; } if(type==TYPE_VIDEO) { retvalue=this->ReceiveFrom(vdata,vlength,address,port); if(retvalue==SOCKET_ERROR) return; ((CVideoNetDlg *)pdlg)->DisplayRemoteFrame(vdata,retvalue); return; } if(type==TYPE_TEXT) { retvalue=this->ReceiveFrom(data,length,address,port); if(retvalue==SOCKET_ERROR) return; // Get host name from the data. // Length of username n=data[1]; int i=0; for(i=0;i<n;i++) { hname[i]=data[i+2]; } hname[i]=0; len=data[n+2] | ( data[n+3]<<8 ); memcpy(mesg,&data[n+4],len); mesg[len]=0; sprintf(str,"%s >> %s ",hname,mesg); // Display message in list box ((CVideoNetDlg *)pdlg)->DisplayMesg(str); return; } }
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrCmdLine, int nCmdShow) #endif { // Checks mem availability and closes background apps // NB: This is approximate amount of memory (in MB) required to start application if ( !EnsureMemAvail( 4 ) ) { MessageBox( GetForegroundWindow(), _T("Not enough mana found!"), _T("Startup error"), MB_OK ); return 0; } // Root, Save and Maps folders iFileName::GetAppPath(gRootPath); gDataPath = gRootPath + _T("Data\\"); gSavePath = gRootPath + _T("Save\\"); gMapsPath = gRootPath + _T("Maps\\"); // Init log manager #ifdef DEBUG_LOG gLogMgr.Init(gRootPath+_T("game.log")); #endif //DEBUG_LOG // Load settings if (!gSettings.Init(lpstrCmdLine)) { MessageBox(NULL, _T("Unable to init game settings!"), NULL, MB_OK); } // Init application uint32 flags = GXLF_LANDSCAPE; if (!gSettings.ForceNoSound() && gSettings.GetEntryValue(CET_SFXVOLUME) != 0) flags |= GXLF_ENABLESOUND; #ifdef OS_WINCE if (gSettings.GetEntryValue(CET_LHANDMAODE)) flags |= GXLF_LHANDER; #endif #ifdef OS_WIN32 flags |= GXLF_DOUBLESIZE; #endif if (!gApp.Init(hInstance,L"Palm Heroes",&gGame,30,flags)){ return -1; } // ShowLogo and intro image (disabled for this version) //iIntroDlg idlg(&gApp.ViewMgr()); //idlg.DoModal(); // Setup global sfx volume if (gApp.SndPlayer().Inited()) { gApp.SndPlayer().SetVolume(gSettings.GetEntryValue(CET_SFXVOLUME)*256/10); } // Setup initial gamma value gApp.Display().SetGamma(1.0f + 0.05f * gSettings.GetEntryValue(CET_DISPGAMMA)); // Init secret dllLib pSecret = (iSecret*)malloc(sizeof(iSecret)); memset(pSecret, 0, sizeof(iSecret)); pSecret->state = (xxc::dll_init( *pCoreHandle ))?1:0; // Init text composer if (!gTextComposer.Init()) { MessageBox(NULL, _T("Unable to init text composer!"), NULL, MB_OK); return -1; } // Init text resources if (!gTextMgr.Init()) { MessageBox(NULL, _T("Unable to init text manager!"), NULL, MB_OK); return -1; } // Init gfx resources and fill secret dll gGfxMgr.SetGamma( gSettings.GetEntryValue(CET_DISPGAMMA) ); if (!gGfxMgr.Load(0,(gDataPath+_T("game.gfx")).CStr(), gSettings.MapSpriteFile()?(iGfxManager::LM_MappedFile):(iGfxManager::LM_Memory))) { MessageBox(NULL, _T("Unable to open sprite file!"), NULL, MB_OK); return -1; } // Init sfx resources if (gSettings.GetEntryValue(CET_SFXVOLUME) != 0 && !gSfxMgr.Init(gDataPath+_T("game.sfx"))) { MessageBox(NULL, _T("Unable to open sound resources file!"), NULL, MB_OK); return -1; } // Registration #if defined(NEED_REGISTRATION) // load bloom bits { iFilePtr pFile = OpenWin32File(gDataPath + L"dumpset.dat"); // key file is missing! check( pFile ); if ( !pFile ) return -1; uint32 bitsSize = pFile->GetSize(); pBloomBits = (uint8*)malloc(bitsSize); pFile->Read(pBloomBits, bitsSize ); } //gSettings.SetActivationKey( iStringT( L"ANWC94TN58FP1ZENT8A6U7GP" )); //gSettings.SetActivationKey( iStringT( L"70W88K22AY382PXVH14CWZME" ));Q6K9CQTRN1YZ5R0874FWU34E //gSettings.SetActivationKey( iStringT( L"Q6K9CQTRN1YZ5R0874FWU34E" )); if (!gSettings.HasActivationKey()) { iDlg_Register rdlg(&gApp.ViewMgr()); rdlg.DoModal(); } #endif // Initialize and start new game if (!gGame.Init(lpstrCmdLine) ) { return -1; } #ifdef OS_WINCE iLightHolder lightHolder; #endif //OS_WINCE // Core loop sint32 retCode = gApp.Run(); // Cleanup gApp.Destroy(); return retCode; }