void CLogSpreadSheet::SetRowColorNotComplete(long nRow) { SetCol(1); SetRow(nRow); SetCol2(10); SetRow2(nRow); SetBlockMode(true); SetBackColor(m_cBackGroundNotComplete); SetBlockMode(false); }
void CLogSpreadSheet::InitSheet() { SetMaxCols(colMax); SetMaxRows(rowMax); SetBackColorStyle(SS_BACKCOLORSTYLE_UNDERGRID); SetTypeEditMultiLine(true); m_nDefaultRowHeight = GetRowHeight(0); InitColumnName(); InitColumnWidth(); SetBlockMode(true); SetGridColor(m_cGridNotComplete); SetBlockMode(false); m_nCurLastLogID = m_daoLogContent.GetLastLogID(); }
int UDPConnection::GetMessage(MsgType *type, void *data, int *max_data_len, int block){ if(!m_Connected) return FALSE; #ifdef WIN32 SetBlockMode(block); #endif struct sockaddr_in source; int source_ln = sizeof(source); int n_read = recvfrom(m_socket, m_buffer, MAX_FULL_BUFFER_SIZE, (block==0? MSG_DONTWAIT: 0), (struct sockaddr *)&source, (socklen_t*)&source_ln); if(n_read<0){ if(block==1){ ERROR_MSG("Error while fetching data\n"); }else{ DEBUG_MSG("No data present\n"); } return FALSE; } // Check of IP address if(EqualIP(&source,(m_ConMode==CONMODE_CLIENT ? &m_server: &m_client))){ MsgType tmpType; // Check of message size if(n_read>=(int)sizeof(long int)){ // Retreiving the message header tmpType = (MsgType)(((long int*)m_buffer)[0]); if(type!=NULL){ *type = tmpType; } // Checks it if(tmpType >= MSGTYPE_LENGTH){ ERROR_MSG("Not a valid header\n"); return FALSE; } if((tmpType == CLOSE_CONNECTION)){ m_Connected = false; return FALSE; } bool pingPongMsg = false; if((tmpType == PING_CONNECTION)){ bHasPing = TRUE; pingPongMsg = true; } if((tmpType == PONG_CONNECTION)){ bHasPong = TRUE; pingPongMsg = true; } // Copy data if(!pingPongMsg){ if(max_data_len!=NULL){ if((*max_data_len)>0){ *max_data_len = (n_read-(int)sizeof(long int)<(*max_data_len)?n_read-(int)sizeof(long int):(*max_data_len)); memcpy(data,((long int*)m_buffer)+1,(*max_data_len)); } } }else{ unsigned int cDataLen = (n_read-(int)sizeof(long int)<MAX_BUFFER_SIZE?n_read-(int)sizeof(long int):MAX_BUFFER_SIZE); if(cDataLen<sizeof(long int)) memset(m_pingBuffer,0,sizeof(long int)); memcpy(m_pingBuffer,((long int*)m_buffer)+1,cDataLen); } return TRUE; }else{ ERROR_MSG("Not a valid message (too short)\n"); } }else{ ERROR_MSG("Bad source IP address\n"); } return FALSE; }
// Wait for an allowed client to connect to the server // if(block) then wait until a right client is connected // else return immediately int UDPConnection::WaitForClient(int block){ if(m_ConMode!=CONMODE_SERVER){ ERROR_MSG("Server not initialized\n"); return FALSE; } DEBUG_MSG("Waiting for client\n"); #ifdef WIN32 SetBlockMode(block); #endif // Recieve data int first = 1; while((block==1)||(first==1)){ if(first==0) sleep(1); DEBUG_MSG("Waiting for client\n"); struct sockaddr_in client; int client_ln = sizeof(client); int n_read = recvfrom(m_socket, m_buffer, MAX_FULL_BUFFER_SIZE, (block==0? MSG_DONTWAIT: 0), (struct sockaddr *)&client, (socklen_t*)&client_ln); if(n_read<0){ ERROR_MSG((block!=0?"Error while fetching data\n":"No client present\n")); return FALSE; } int i; for(i=0;i<m_nb_allowed_client;i++){ if(EqualIP(&client,&(m_allowed_client[i]))){ memcpy(&m_client,&client,client_ln); m_Connected = true; DEBUG_MSG("Sending accept connection: "); DEBUG_CMD(PrintIP(&m_client)); if(!SendMessage(ACCEPT_CONNECTION,NULL,0)){ ERROR_MSG("Sending accpeting connection\n"); m_Connected = false; } DEBUG_MSG("Client found: "); DEBUG_CMD(PrintIP(&client)); DEBUG_MSG("\n"); return TRUE; } } if(!SendMessage(REFUSE_CONNECTION,NULL,0)){ ERROR_MSG("Sending refusing connection\n"); } ERROR_MSG("Unallowed client was found: "); ERROR_CMD(PrintIP(&client)); first = 0; } return FALSE; }