/**************************GLOW MAP**************************/ cDirectX9GlowMap::cDirectX9GlowMap() { XREFOBJECT(cDirectX9GlowMap); IDirect3DStateBlock9* pkBlock = 0; if( FAILED(gpkDirect3DDevice->BeginStateBlock()) ) { ReportBug("Failed to record state blocks.B","cDirectX9DetailMap"); return; } gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT ); gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_ADD ); if( FAILED(gpkDirect3DDevice->EndStateBlock(&pkBlock)) ) { ReportBug("Failed to record state blocks.E","cDirectX9DetailMap"); return; } mpvStateBlock = (void*)pkBlock; X_BREAK_IF(!mpvStateBlock); }
/************************DETAIL MAP**************************/ cDirectX9DetailMap::cDirectX9DetailMap() { XREFOBJECT(cDirectX9DetailMap); IDirect3DStateBlock9* pkBlock = 0; if( FAILED(gpkDirect3DDevice->BeginStateBlock()) ) { ReportBug("Failed to record state blocks.B","cDirectX9DetailMap"); return; } gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); /* use the low-frequency texture coordinates */ /* assumed */ gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT ); gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED ); // use the high-frequency texture coordinates gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1 ); if( FAILED(gpkDirect3DDevice->EndStateBlock(&pkBlock)) ) { ReportBug("Failed to record state blocks.E","cDirectX9DetailMap"); return; } mpvStateBlock = (void*)pkBlock; X_BREAK_IF(!mpvStateBlock); }
/*********************SHPERE MAP*****************************/ cDirectX9SphereMap::cDirectX9SphereMap( const f32* m ) { XREFOBJECT(cDirectX9SphereMap); IDirect3DStateBlock9* pkBlock = 0; if( FAILED(gpkDirect3DDevice->BeginStateBlock()) ) { ReportBug("Failed to record state blocks.B","cDirectX9SphereMap"); return; } gpkDirect3DDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE); gpkDirect3DDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); gpkDirect3DDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); gpkDirect3DDevice->SetTransform( D3DTS_TEXTURE0, reinterpret_cast<const D3DMATRIX*>(m) ); gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL ); if( FAILED(gpkDirect3DDevice->EndStateBlock(&pkBlock)) ) { ReportBug("Failed to record state blocks.E","cDirectX9SphereMap"); return; } mpvStateBlock = (void*)pkBlock; X_BREAK_IF(!mpvStateBlock); }
void cDirectX9LLShader::set( cMaterial* m, bool reset ) { if(reset) { if( mpkVertexShader ) { gpkDirect3DDevice->GetVertexShader(&mpkOldVertexShader); if( FAILED(gpkDirect3DDevice->SetVertexShader(mpkVertexShader)) ) ReportBug( "Error setting vertex shader", "cDirectX9LLShader::set" ); } if( mpkPixelShader ) { if( FAILED(gpkDirect3DDevice->SetPixelShader(mpkPixelShader)) ) ReportBug( "Error setting pixel shader", "cDirectX9LLShader::set" ); } } if( mpkCallback ) mpkCallback->setShaderConst(this); if( mpkBaseStates ) mpkBaseStates->set(m,reset); }
void CGUIReportBug::OnCommand( const char *command ) { if ( !Q_stricmp( command, "report" ) ) { static BugReport report; CBasePlayer *pPlayer = CBasePlayer::GetLocalPlayer(); if ( pPlayer ) { Q_strncpy( report.author, "name", sizeof( report.author ) ); report.origin = pPlayer->GetAbsOrigin(); } else { Q_strncpy( report.author, "unknown name", sizeof( report.author ) ); } Q_strncpy( report.mapName, engine->GetLevelName(), sizeof( report.mapName ) ); m_Title->GetText( report.title, sizeof( report.title ) ); m_Description->GetText( report.description, sizeof( report.description ) ); ReportBug( report ); SetVisible( false ); } else if ( !Q_stricmp( command, "cancel" ) ) { Cancel(); } else { BaseClass::OnCommand( command ); } }
/**********************LIGHT MAP*****************************/ cDirectX9LightMap::cDirectX9LightMap( iShader::STDSHADERS eType ) { XREFOBJECT(cDirectX9LightMap); X_BREAK_IF( eType != iShader::SHADER_LIGHTMAP && eType != iShader::SHADER_LIGHTMAP2X && eType != iShader::SHADER_LIGHTMAP4X && eType != iShader::SHADER_LIGHTMAPDYNAMIC ); IDirect3DStateBlock9* pkBlock = 0; if( FAILED(gpkDirect3DDevice->BeginStateBlock()) ) { ReportBug("Failed to record state blocks.B","cDirectX9LightMap"); return; } if( eType == iShader::SHADER_LIGHTMAPDYNAMIC ) { gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); } else { gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); gpkDirect3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); } gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_CURRENT ); gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_TEXTURE ); if( eType == iShader::SHADER_LIGHTMAP || eType == iShader::SHADER_LIGHTMAPDYNAMIC ) gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE ); else if( eType == iShader::SHADER_LIGHTMAP2X ) gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE2X ); else gpkDirect3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE4X ); if( FAILED(gpkDirect3DDevice->EndStateBlock(&pkBlock)) ) { ReportBug("Failed to record state blocks.E","cDirectX9LightMap"); return; } mpvStateBlock = (void*)pkBlock; X_BREAK_IF(!mpvStateBlock); }
static void* AcceptSockets(void*) // accepts incoming connections from users { try { while(1) { char* time = GetTimeInfo()+SKIPWEEKDAY; TCPSocket *sock = serverSocket->accept(); LaunchClient((void*)sock); } } catch (SocketException &e) {printf("accept busy\r\n"); ReportBug("***Accept busy\r\n");} exit(1); return NULL; }
//------------------------------------------------------------------------------ // _createMipMaps //------------------------------------------------------------------------------ void cDirectX9Texture::_createMipMaps( ) { if( mpkTexture ) { if( muFlags & HasHardwareMipMaps ) mpkTexture->GenerateMipSubLevels(); return; cStr DllName; DllName.format( X_Text("d3dx9_%d.dll"), 15, ((s32)D3DX_SDK_VERSION) ); HINSTANCE h = LoadLibrary( DllName.c_str() ); if( !h ) { ReportBug( ERROR6, "_createMipMaps" ); goto quit; } D3DXFilterTexturePtr FilterFunc = (D3DXFilterTexturePtr)GetProcAddress( (HMODULE)h, D3DXFilterTexture_FuncName ); if( !FilterFunc ) { ReportBug( ERROR7, "_createMipMaps" ); goto quit; } if( FAILED( FilterFunc( mpkTexture, 0, (UINT)-1, (UINT)-1) ) ) { ReportBug( ERROR8, "_createMipMaps" ); goto quit; } quit: FreeLibrary(h); return; } return; }
//------------------------------------------------------------------------------ // _createRenderTarget //------------------------------------------------------------------------------ void cDirectX9Texture::_createRenderTarget() { mkDimension.dx = (i2d)getPow2Dimension(mkDimension.dx); mkDimension.dy = (i2d)getPow2Dimension(mkDimension.dy); IDirect3DSurface9* bbuff = 0; if( SUCCEEDED( gpkDirect3DDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &bbuff ) ) ) { D3DSURFACE_DESC desc; bbuff->GetDesc(&desc); D3DFORMAT d3dformat = desc.Format; if ( d3dformat == D3DFMT_X8R8G8B8 ) d3dformat = D3DFMT_A8R8G8B8; bbuff->Release(); if( FAILED( gpkDirect3DDevice->CreateTexture( mkDimension.dx, mkDimension.dy, 1, D3DUSAGE_RENDERTARGET, d3dformat, D3DPOOL_DEFAULT, &mpkTexture, 0 ) ) ) ReportBug( ERROR4, "_createRenderTarget" ); } else ReportBug( ERROR5, "_createRenderTarget" ); }
//------------------------------------------------------------------------------ // lock //------------------------------------------------------------------------------ void* cDirectX9Texture::lock( bool bwriteaccess ) { if (!mpkTexture) return 0; D3DLOCKED_RECT rect; HRESULT hr = mpkTexture->LockRect(0, &rect, 0, bwriteaccess ? 0 : D3DLOCK_READONLY ); if (FAILED(hr)) { ReportBug( ERROR9, "_createMipMaps" ); return 0; } return rect.pBits; }
//------------------------------------------------------------------------------ // _copyTexture //------------------------------------------------------------------------------ bool cDirectX9Texture::_copyTexture( cSoftwareTexture* Image ) { if ( mpkTexture && Image ) { D3DSURFACE_DESC desc; mpkTexture->GetLevelDesc(0, &desc); mkDimension.dx = desc.Width; mkDimension.dy = desc.Height; bool SurfaceHasSameSize = (mkDimension == Image->getDimension()); if ( desc.Format == D3DFMT_A1R5G5B5 ) return _copyTo16BitTexture( Image, SurfaceHasSameSize ); else if (desc.Format == D3DFMT_A8R8G8B8) return _copyTo32BitTexture( Image, SurfaceHasSameSize ); else ReportBug( ERROR10, "_copyTexture" ); } return true; }
void ReadNewUser() { userFirstLine = 1; inputCount = 0; ClearUserVariables(); ResetTopicSystem(); // set his random seed bool hasUpperCharacters; unsigned int rand = (unsigned int) Hashit((unsigned char *) loginID,strlen(loginID),hasUpperCharacters); char word[MAX_WORD_SIZE]; randIndex = rand & 4095; sprintf(word,"%d",randIndex); SetUserVariable("$randindex",word ); strcpy(word,computerID); word[0] = toUppercaseData[(unsigned char)word[0]]; SetUserVariable("$bot",word ); SetUserVariable("$login",loginName); sprintf(readBuffer,"^%s",computerID); WORDP D = FindWord(readBuffer,0,LOWERCASE_LOOKUP); if (!D) { ReportBug("Cannot find bot %s\r\n",computerID); return; } int oldjump = jumpIndex; char* macroArgumentList = AllocateBuffer(); *macroArgumentList = 0; globalDepth = 2; unsigned int result; currentOutputBase = macroArgumentList; DoFunction(D->word,macroArgumentList,macroArgumentList,result); globalDepth = 0; jumpIndex = oldjump; // return to old error handler FreeBuffer(); }
//------------------------------------------------------------------------------ // ctor //------------------------------------------------------------------------------ cDirectX9Texture::cDirectX9Texture( cSoftwareTexture *Image, u32 flags ) { X_BreakOutIf(!gpkDirect3DDevice); RefObjectInit(cDirectX9Texture); bool generateMipLevels = (flags & TCF_MIPMAPS) != 0; if (Image) { _createTexture( Image, flags ); if(mpkTexture) { if ( _copyTexture( Image ) && generateMipLevels ) { _createMipMaps(); muFlags |= HasMipMaps; } } else ReportBug( ERROR1, "cDirectX9Texture" ); } }
//------------------------------------------------------------------------------ // _copyTo16BitTexture //------------------------------------------------------------------------------ bool cDirectX9Texture::_copyTo16BitTexture( cSoftwareTexture *Image, bool SurfaceHasSameSize ) { D3DLOCKED_RECT rect; HRESULT hr = mpkTexture->LockRect(0, &rect, 0, 0); if (FAILED(hr)) { ReportBug( ERROR13, "_copyTo16BitTexture" ); return false; } s16* dest = (s16*)rect.pBits; s16* source = (s16*)Image->lock(); miPitch = rect.Pitch; s16 pitch = rect.Pitch / 2; size2_x ImageSize = Image->getDimension(); if (SurfaceHasSameSize) { if (Image->getColorFormat() == CF_A1R5G5B5) { for ( s32 x=0; x<ImageSize.dx; ++x ) for ( s32 y=0; y<ImageSize.dy; ++y ) dest[x + y*pitch] = source[x + y*ImageSize.dx]; } else { for ( s32 x=0; x<ImageSize.dx; ++x ) for ( s32 y=0; y<ImageSize.dy; ++y ) { cColor pix = Image->getPixel(x,y); dest[x + y*pitch] = pix.toA1R5G5B5(); } } } else { f32 factorX = (f32)ImageSize.dx / (f32)mkDimension.dx; f32 factorY = (f32)ImageSize.dy / (f32)mkDimension.dy; f32 sy; if (Image->getColorFormat() == CF_A1R5G5B5) { for (s32 x=0; x<mkDimension.dx; ++x) { sy = 0.0f; for (s32 y=0; y<mkDimension.dy; ++y) { dest[(s32)(y*pitch + x)] = source[(s32)(((s32)sy)*ImageSize.dx + x*factorX)]; sy+=factorY; } } } else { for (s32 x=0; x<mkDimension.dx; ++x) { sy = 0.0f; for (s32 y=0; y<mkDimension.dy; ++y) { cColor pix = Image->getPixel((s32)(x*factorX), (s32)sy); dest[(s32)(y*pitch + x)] = pix.toA1R5G5B5(); sy+=factorY; } } } } hr = mpkTexture->UnlockRect(0); if (FAILED(hr)) { ReportBug( ERROR14, "_copyTo16BitTexture" ); return false; } return true; }
//------------------------------------------------------------------------------ // _createTexture //------------------------------------------------------------------------------ void cDirectX9Texture::_createTexture( cSoftwareTexture *image, u32 flags ) { size2_x d = image? image->getDimension() : mkDimension; mkDimension.dx = (i2d)getPow2Dimension(d.dx); mkDimension.dy = (i2d)getPow2Dimension(d.dy); D3DFORMAT Format = D3DFMT_A1R5G5B5; switch( filterFlag(flags) ) { case TCF_32B: Format = D3DFMT_A8R8G8B8; break; case TCF_QUALITY: if( image ) { switch( image->getColorFormat() ) { case D3DFMT_X8R8G8B8: case D3DFMT_A8R8G8B8: case D3DFMT_R8G8B8: Format = D3DFMT_A8R8G8B8; break; case D3DFMT_A1R5G5B5: case D3DFMT_R5G6B5: Format = D3DFMT_A1R5G5B5; break; default: ReportBug( ERROR2, "_createTexture" ); return; }; } else { Format = flags & TCF_32B? D3DFMT_A8R8G8B8 : D3DFMT_A1R5G5B5; } break; case TCF_16B: case TCF_SPEED: Format = D3DFMT_A1R5G5B5; break; }; if(Format == D3DFMT_A1R5G5B5 ) meColorFormat = CF_A1R5G5B5; else meColorFormat = CF_A8R8G8B8; bool miplevels = ( flags & TCF_MIPMAPS ) ? 1 : 0; u32 usage = ( ( flags & TCF_USE_HARDWARE_MIPMAPS ) && X_SharedPtr(iRenderer)->isFeatureSupported(FS_AUTOGEN_MIP_MAPS) ) ? D3DUSAGE_AUTOGENMIPMAP : 0; if(usage) muFlags |= HasHardwareMipMaps; HRESULT rval = gpkDirect3DDevice->CreateTexture( mkDimension.dx, mkDimension.dy, miplevels ? 0 : 1, usage, Format, D3DPOOL_MANAGED, &mpkTexture, 0 ); if( FAILED( rval ) ) { if( Format == D3DFMT_A8R8G8B8 ) rval = gpkDirect3DDevice->CreateTexture( mkDimension.dx, mkDimension.dy, miplevels ? 0 : 1, usage, D3DFMT_A1R5G5B5, D3DPOOL_MANAGED, &mpkTexture, 0 ); } if( FAILED( rval ) ) { ReportBug( ERROR3, "_createTexture" ); return; } D3DLOCKED_RECT rc; mpkTexture->LockRect( 0, &rc, 0, 0 ); miPitch = rc.Pitch; mpkTexture->UnlockRect(0); }
static void* HandleTCPClient(void *sock1) // individual client, data on STACK... might overflow... { clock_t starttime = ElapsedMilliseconds(); char* memory = (char*) malloc(2*SERVERTRANSERSIZE+2); // our data in 1st chunk, his reply info in 2nd if (!memory) return NULL; // ignore him if we run out of memory char* output = memory+SERVERTRANSERSIZE; *output = 0; char* buffer; TCPSocket *sock = (TCPSocket*) sock1; char IP[20]; try { strcpy(memory,sock->getForeignAddress().c_str()); // get IP address strcpy(IP,memory); buffer = memory + strlen(memory) + 1; // use this space after IP for messaging } catch (SocketException e) { ReportBug("Socket errx"); cerr << "Unable to get port" << endl; return Done(sock,memory); } char timeout = ' '; char userName[500]; *userName = 0; char* user; char* bot; char* msg; char* prior = ""; // A user name with a . in front of it means tie it with IP address so it remains unique try{ unsigned int len = sock->recv(buffer, SERVERTRANSERSIZE-50); // leave ip address in front alone memset(buffer+len,0,3); user = buffer; bot = user + strlen(user) + 1; msg = bot + strlen(bot) + 1; if (!*user) { if (*bot == '1' && bot[1] == 0) // echo test to prove server running (generates no log traces) { strcpy(output,"1"); return Done(sock,memory); } ReportBug("%s %s bot: %s msg: %s NO USER ID \r\n",IP,GetTimeInfo()+SKIPWEEKDAY,bot,msg); strcpy(output,"[you have no user id]\r\n"); return Done(sock,memory); } if (Blacklisted(memory,user)) // if he is blacklisted, we ignore him { PartialLogin(user,memory); // sets LOG file so we record his messages Log(SERVERLOG,"%s %s/%s %s msg: %s BLOCKED \r\n",IP,user,bot,GetTimeInfo()+SKIPWEEKDAY,msg); strcpy(output,"[ignoring you.]\r\n"); // response is JUST this Log(STDUSERLOG,"blocked %s => %s\r\n",msg,output); return Done(sock,memory); } strcpy(userName,user); // wait to get attention of chatbot server, timeout if doesnt come soon enough bool ready = ClientGetChatLock( ANSWERTIMELIMIT - (ElapsedMilliseconds() - starttime) ); // chatlock ... if (!ready) // if it takes to long waiting to get server attn, give up { PartialLogin(userName,memory); // sets LOG file so we record his messages switch(random(4)) { case 0: strcpy(output,"Hey, sorry. Had to answer the phone. What was I saying?"); break; case 1: strcpy(output,"Hey, sorry. There was a salesman at the door. Where were we?"); break; case 2: strcpy(output,"Hey, sorry. Got distracted. What did you say?"); break; case 3: strcpy(output,"Hey, sorry. What did you say?"); break; } Log(STDUSERLOG,"Timeout waiting for service: %s => %s\r\n",msg,output); return Done(sock,memory); } } catch (...) { ReportBug("***%s client presocket failed %s\r\n",IP,GetTimeInfo()+SKIPWEEKDAY); return Done(sock,memory); } clock_t serverstarttime = ElapsedMilliseconds(); try{ chatWanted = true; // indicate we want the chatbot server - no other client can get chatLock while this is true clientBuffer = memory; int remain = ANSWERTIMELIMIT - (ElapsedMilliseconds() - starttime); if (!ClientWaitForServer(memory,msg,remain)) // release lock, loop wait for data, and maybe we give up waiting for him { timeout = '*'; switch(random(4)) { case 0: strcpy(output,"Hey, sorry. Had to answer the phone. What was I saying?"); break; case 1: strcpy(output,"Hey, sorry. There was a salesman at the door. Where were we?"); break; case 2: strcpy(output,"Hey, sorry. Got distracted. What did you say?"); break; case 3: strcpy(output,"Hey, sorry. What did you say?"); break; } } unsigned int len = strlen(output); if (len) sock->send(output, len); prior = output + len + 1; // bot prior message to us } catch (...) { printf("client socket fail\r\n"); ReportBug("***%s client socket failed %s \r\n",IP,GetTimeInfo()+SKIPWEEKDAY);} delete sock; char* date = GetTimeInfo()+SKIPWEEKDAY; date[15] = 0; // suppress year clock_t endtime = ElapsedMilliseconds(); char* prior1 = prior + strlen(prior) + 1; int volleys = atoi(prior1); if (*msg) Log(SERVERLOG,"%c %s %s/%s %s time:%d/%d v:%d msg: %s => %s <= %s\n",timeout,IP,user,bot,date, (int)(endtime - starttime),(int)(endtime - serverstarttime),volleys,msg,output,prior); else Log(SERVERLOG,"%c %s %s/%s %s start => %s <= %s\n",timeout,IP,user,bot,date,output,prior); free(memory); #ifndef WIN32 pthread_exit(0); #endif return NULL; }
static void* MainChatbotServer() { sprintf(serverLogfileName,"LOGS/serverlog%d.txt",port); ServerStartup(); // get initial control over the mutex so we can start. - on linux if thread dies, we must reacquire here // we now own the chatlock clock_t lastTime = ElapsedMilliseconds(); if (setjmp(scriptJump[MAIN_RECOVERY])) // crashes come back to here { printf("***Server exception\r\n"); ReportBug("***Server exception\r\n"); #ifdef WIN32 char* bad = GetUserVariable("$crashmsg"); if (*bad) strcpy(outputFeed,bad); else strcpy(outputFeed,"Hey, sorry. I forgot what I was thinking about."); ServerTransferDataToClient(""); #endif ResetBuffers(); // in the event of a trapped bug, return here, we will still own the chatlock } chatbotExists = true; // if a client can get the chatlock now, he will be happy Log(SERVERLOG,"Server ready\r\n"); printf("Server ready: %s\r\n",serverLogfileName); #ifdef WIN32 _try { // catch crashes in windows #endif int counter = 0; while (1) { ServerGetChatLock(); startServerTime = ElapsedMilliseconds(); // chatlock mutex controls whether server is processing data or client can hand server data. // That we now have it means a client has data for us. // we own the chatLock again from here on so no new client can try to pass in data. // CLIENT has passed server in globals: clientBuffer (ip,user,bot,message) // We will send back his answer in clientBuffer, overwriting it. char user[MAX_WORD_SIZE]; char bot[MAX_WORD_SIZE]; char* ip = clientBuffer; char* ptr = ip; // incoming is 4 strings together: ip, username, botname, message ptr += strlen(ip) + 1; // ptr to username strcpy(user,ptr); // allow user var to be overwriteable, hence a copy ptr += strlen(ptr) + 1; // ptr to botname strcpy(bot,ptr); ptr += strlen(ptr) + 1; // ptr to message strcpy(inputFeed,ptr); // xfer user message to our incoming feed echo = false; PerformChat(user,bot,inputFeed,ip,outputFeed); // this takes however long it takes, exclusive control of chatbot. #ifdef STATSERVER clock_t now = ElapsedMilliseconds(); if ( (now / 1000) > (lastTime / 1000)) // starting different second { printf("%d\r\n",counter); counter = 0; lastTime = now; } ++counter; if ((now-startServerTime) > 2000) { printf("Compute Stall? %d\r\n",now-startServerTime); } #endif ServerTransferDataToClient(priorMessage); } #ifdef WIN32 }_except (true) { ReportBug("crash\r\n"); Crash();} #endif return NULL; }
void WriteUserData(char* said) { if (!topicNumber) return; // no topics ever loaded or we are not responding char ptr[MAX_WORD_SIZE]; sprintf(ptr,"USERS/topic_%s_%s.txt",loginID,computerID); char name[MAX_WORD_SIZE]; sprintf(name,"USERS/fact_%s.txt",loginID); // Backup allows one to ":revert" for debugging - if you see a bad answer and revert, you can reenter your data while tracing... if (!server) { CopyFile2File("TMP/topics.tmp",ptr,false); // make backup of current topic in single user mode- aids in debugging CopyFile2File("TMP/facts.tmp",name,false); // make backup of current topic facts in single user mode- aids in debugging } FILE* out = fopen(ptr,"wb"); if (!out) { #ifdef WIN32 system("mkdir USERS"); #endif out = fopen(ptr,"wb"); if (!out) { ReportBug("cannot open user state file %s to write\r\n",ptr); return; } } fprintf(out,"%s\n",saveVersion); // format validation stamp // turn off uservars and dump user vars values WriteTopicData(out); // recently used messages unsigned int i; int start = humanSaidIndex - 20; if (start < 0) start = 0; for (i = start; i < humanSaidIndex; ++i) fprintf(out,"%s\n",NLSafe(humanSaid[i])); // what he said indented 3 fprintf(out,"#end usr\n"); start = chatbotSaidIndex - 20; if (start < 0) start = 0; for (i = start; i < chatbotSaidIndex; ++i) fprintf(out,"%s\n",NLSafe(chatbotSaid[i])); // what we replied indented 1 fprintf(out,"#end bot\n"); // write out fact sets fprintf(out,"%x #sets flags\n",(unsigned int) setControl); for (i = 1; i < MAX_FIND_SETS; ++i) { if (!(setControl & (uint64) (1 << i))) continue; // purely transient stuff // remove dead references FACT** set = factSet[i]; unsigned int count = (ulong_t) set[0]; unsigned int j; for (j = 1; j <= count; ++j) { FACT* F = set[j]; if (!F || F->properties & (TRANSIENTFACT | DEADFACT)) { memcpy(&set[j],&set[j+1],sizeof(FACT*) * (count - j)); --count; --j; } } if (!count) continue; fprintf(out,"Fact %d %d \r\n",i,count); // set and count for (j = 1; j <= count; ++j) { char word[MAX_WORD_SIZE]; fprintf(out,"%s\n",WriteFact(factSet[i][j],false,word)); } } fclose(out); // now write user facts, if any have changed. Otherwise file is valid as it stands. bool written = (factFree == userFactBase); while (factFree > topicFacts) { // see if any facts are actually important and "new" if (!written && !(factFree->properties & (TRANSIENTFACT|DEADFACT))) { WriteFacts(fopen(name,"wb"),topicFacts); // write facts from here on down written = true; } FreeFact(factFree--); // erase new facts } }