//签到时处理请求 long CSingInServer::SignInProcess(TSSmartDocEx *pDocEx, TSCmdBuffer *pBuffer, long nPort, TSSmartTask *pTask) { long nAuthID = 0 ; int n = pDocEx->nPortNo ; TSDeviceInfo DevInfo; ZeroMemory(&DevInfo, sizeof(DevInfo)); if( pDocEx->nChildDoc > 1 ) { for(int i=1; i< pDocEx->nChildDoc; i++) { if( pDocEx->pChildDoc[i]->m_nParentID > 0 && pDocEx->pChildDoc[i]->m_nSMTPort == nPort && (pDocEx->pChildDoc[i]->m_nStatus == 0 || pDocEx->pChildDoc[i]->m_nStatus == 1) ) { n = i ; memcpy(&DevInfo, &pDocEx->pChildDoc[i]->DeviceInfo, sizeof(DevInfo)); break; } } } else { memcpy(&DevInfo, &pDocEx->pChildDoc[n]->DeviceInfo, sizeof(DevInfo)); DevInfo.nLevel = 0 ; DevInfo.sLevelArray[1] = (unsigned char)nPort; } CCheckBlackVersion Check; int nTemp = pDocEx->nPortNo ; pDocEx->nPortNo = n; if( Check.SignInDown(pDocEx->pChildDoc[n], pBuffer) != RET_OK ) { pDocEx->nPortNo = nTemp ; pDocEx->pChildDoc[n]->m_nSignIn = RET_BLACKLIST_ERROR ; return RET_BLACKLIST_ERROR; } if( ProcessData(pDocEx, pTask, pBuffer) != RET_OK ) { //printf("签到不成功!\n"); pDocEx->nPortNo = nTemp ; pDocEx->pChildDoc[n]->m_nSignIn = RET_BLACKLIST_ERROR ; return RET_BLACKLIST_ERROR; } if( SignIn && pDocEx->pChildDoc[n]->m_nSignIn != 1 ) { SignIn(pDocEx->pChildDoc[n]); } GetCurDateTime(pDocEx->pChildDoc[n]->m_szSignInTime); pDocEx->pChildDoc[n]->m_nSignIn = 1 ; pDocEx->nPortNo = nTemp ; return RET_OK; }
int procFunc(int p) { int message; if (CheckAuthority(p, inOperation)) switch(p) { case 0 : message = SignIn(); break; case 1 : message = Login(); break; case -2 : message = Finalization(); break; case 2 : message = Logout(); break; case -3 : message = SearchBookByKeyword();break; case 3 : message = BorBook(); break; case 4 : message = RetBook(); break; case -4 : message = ShowSpecificBook(); break; case 5 : message = ChangeNickName(); break; case 6 : message = ChangePassword(); break; case 7 : message = AddBook(); break; case 8 : message = DelBook(); break; case 9 : message = EditBook(); break; case 10 : message = DelUser(); break; case -10 : message = 0; break; case 11 : message = ChangeUserAuthority(); break; default : break; } return message; }
void App::Init() { light.Off(); //初始化wifi WifiInit(); TaskManager::DelayS(5); if(!SignIn()) com1<<"sign in fail!!!!!!!!!!!!\n\n\n"; com1<<"initialize complete!\n"; }
//----------------------------------------------------------------------------- // Function: PrintMenu // Purpose: Prints a menu, retrieves the user selection, calls the handler, loops. // Returns when "Quit" is selected from the menu // Parameters: None // void RunMenu() { HRESULT hr; WCHAR wzBuff[INPUT_BUFSIZE]; int nInput; // Continuously show the menu to user and respond to their request // while (TRUE) { PrintMenu(); fflush(stdin); hr = StringCbGets(wzBuff, sizeof(wzBuff)); if (FAILED(hr)) { wprintf (L"Invalid input, expected a number between 1 and 25 or Q to quit.\n"); continue; } if ((wcsncmp(wzBuff, L"Q", INPUT_BUFSIZE) == 0) || (wcsncmp(wzBuff, L"q", INPUT_BUFSIZE) == 0)) { // break out of while loop. // break; } // since wtoi can't distinguish between 0 and an error, note that valid values start at 1, not 0 nInput = _wtoi(wzBuff); if (nInput < 1 || nInput > 25) { printf ("Invalid input, expected a number between 1 and 25 or Q to quit.\n"); continue; } switch (nInput) { case 1: SignIn(); break; case 2: SignOut(); break; case 3: SignInOptions(); break; case 4: SetEndpointName(); break; case 5: GetEndpointName(); break; case 6: DisplayEndpointInformation(); break; case 7: EnumeratePeopleNearMe(); break; case 8: AddEndpointAsContact(); break; case 9: ExportContact(); break; case 10: ParseContact(); break; case 11: ImportContact(); break; case 12: DeleteContact(); break; case 13: EnumContacts(); break; case 14: SetWatching(); break; case 15: SetWatchPermissions(); break; case 16: GetPresenceInformation(); break; case 17: SetPresenceInformation(); break; case 18: SubscribeEndpointData(); break; case 19: UnsubscribeEndpointData(); break; case 20: PublishEndpointObject(); break; case 21: DeleteEndpointObject(); break; case 22: RegisterApplication(); break; case 23: UnregisterApplication(); break; case 24: DisplayApplicationRegistrations(); break; case 25: SendInvite(); break; default: wprintf(L"Invalid selection.\n"); break; } //Pause so that our output doesn't scroll //off the screen before the user gets a change to //read it. wprintf(L"\n\nPress <ENTER> to continue.\n"); fflush(stdin); (void)StringCbGets(wzBuff, sizeof(wzBuff)); } }
long CSingInServer::ProcessData(TSSmartDocEx *pDocEx, TSSmartTask *pTask, TSCmdBuffer *pBuffer) { bool bResult = false; CTime tm; int len=0,i=0; int E_number=0; unsigned char Clock[16]; unsigned char Plain[256],ID[16]; char ErrMsg[256]; memset(ID, 0x00,sizeof ID); memset(Clock, 0x00,sizeof Clock); memset(Plain, 0x00,sizeof Plain); memset(ErrMsg,0x00,sizeof ErrMsg); sprintf(ErrMsg,"处理终端%.8X签到任务\n",pDocEx->pChildDoc[pDocEx->nPortNo]->m_nAuthID); printf(ErrMsg); WriteLog(ErrMsg); m_nIndex = pDocEx->nPortNo; memset(ErrMsg,0x00,sizeof ErrMsg); //由于需要金仕达确认是否可以签到,故将签到任务提前到前面 int ret = 0; E_number = 1; for(i=0; i<3; i++) { tm=CTime::GetCurrentTime(); Clock[0] = tm.GetYear()-2000; Clock[1] = tm.GetMonth(); Clock[2] = tm.GetDay(); Clock[3] = tm.GetHour(); Clock[4] = tm.GetMinute(); Clock[5] = tm.GetSecond(); Clock[6] = tm.GetDayOfWeek(); MakeBuf_SetClock(&pDocEx->pChildDoc[pDocEx->nPortNo]->DeviceInfo, pBuffer,Clock); pBuffer->nTimeOut1 = 1000; pBuffer->nTimeOut2 = 1000; //Modified by hhd at 2006-01-20,added return code ret=SendRequest(pDocEx->pChildDoc[m_nIndex], pBuffer); if(ret==RET_OK) { ret=UnMakeDeviceBuffer(pBuffer); if(ret==RET_OK) { sprintf(ErrMsg,"下传终端%.8X时钟成功!\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID); printf(ErrMsg); WriteLog(ErrMsg); bResult = true; break; } else { sprintf(ErrMsg,"-----!!!!校验%.8X返回包失败-时钟!错误码=[%d]\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID,ret); printf(ErrMsg); Sleep(1000); } } else { sprintf(ErrMsg,"-----!!!!下传终端%.8X时钟失败!错误码=[%d]\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID,ret); printf(ErrMsg); Sleep(1000); } } if( !bResult ) { printf("-----!!!!下传终端%.8X时钟失败!\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID); ReportLog(pDocEx->pChildDoc[m_nIndex], pTask, RET_CLOCK_ERROR, "终端机签到", "终端机签到 ---校对时钟失败!"); pDocEx->pChildDoc[pDocEx->nPortNo]->m_nSignIn = RET_CLOCK_ERROR ; return RET_CLOCK_ERROR; } char szKeyBuf[256]; memset(Plain, 0x00, sizeof(Plain)); memset(szKeyBuf, 0x00, sizeof(szKeyBuf)); GetAuthKey(szKeyBuf); if( !strlen(szKeyBuf) ) //向金仕达取授权密钥失败 add by dengjun 20060616 { strcpy(ErrMsg,"向金仕达取授权密钥失败"); printf("%s\n",ErrMsg); WriteLog(ErrMsg); } len = strlen(szKeyBuf)/2; SVC_DSP_2_HEX((BYTE*)szKeyBuf, Plain, len); //设置授权信息 bResult = false; Sleep(5000); //Modified by dengjun 20060616 update Sleep(250) to Sleep(5000) memset(ErrMsg,0x00,sizeof ErrMsg); //Modified by hhd at 2006-01-20,added return code for(i=0; i<3; i++) { SVC_DSP_2_HEX((unsigned char *)pDocEx->pChildDoc[pDocEx->nPortNo]->m_szDeviceID, ID, 4); //modified by lina 20050308 SmartEncrypt(E_number,ID,Plain); MakeBuf_SetWorkingKey(&pDocEx->pChildDoc[pDocEx->nPortNo]->DeviceInfo,pBuffer,Plain,E_number); pBuffer->nTimeOut1 = 1000 ; pBuffer->nTimeOut2 = 1000; ret=SendRequest(pDocEx->pChildDoc[pDocEx->nPortNo], pBuffer); if(ret==RET_OK) { ret=UnMakeDeviceBuffer(pBuffer); if(ret==RET_OK) { sprintf(ErrMsg,"-----设置终端%.8X授权信息成功!\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID); printf(ErrMsg); WriteLog(ErrMsg); bResult = true; break; } else { sprintf(ErrMsg,"-----!!!!校验%.8X返回包失败-授权!错误码=[%d]\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID,ret); printf(ErrMsg); Sleep(2500); } } Sleep(1000); } if( !bResult ) { printf("-----!!!!设置终端%.8X授权信息失败!\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID); ReportLog(pDocEx->pChildDoc[m_nIndex], pTask, RET_NOT_AUTH, "终端机签到", "终端机签到 ---设置授权信息失败!"); pDocEx->pChildDoc[pDocEx->nPortNo]->m_nSignIn = RET_NOT_AUTH ; return RET_NOT_AUTH; } if((ret=SignIn(pDocEx->pChildDoc[pDocEx->nPortNo])) != RET_OK) { sprintf(ErrMsg,"后台不允许签到[ErrCode=%ld]!!!!!!!!!!!!!!!\n",ret); printf(ErrMsg); WriteLog(ErrMsg); return RET_ERROR_AUTH;//25:后台不允许签到; } Sleep(3000); //设置消费开关 bResult = false; for(i=0; i<3; i++) { MakeBuf_SetComsumeFlag(&pDocEx->pChildDoc[pDocEx->nPortNo]->DeviceInfo, pBuffer, 1); pBuffer->nTimeOut1 = 1000 ; pBuffer->nTimeOut2 = 1000; ret=SendRequest(pDocEx->pChildDoc[pDocEx->nPortNo], pBuffer); if(ret==RET_OK) { ret=UnMakeDeviceBuffer(pBuffer); if(ret==RET_OK) { bResult = true; break; } else { sprintf(ErrMsg,"-----!!!!校验%.8X返回包失败-消费开关!错误码=[%d]\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID,ret); printf(ErrMsg); WriteLog(ErrMsg); Sleep(1500); } } else { Sleep(200); } } if( !bResult ) { printf(ErrMsg,"----!!!!设备%.8X签到失败!\n",pDocEx->pChildDoc[m_nIndex]->m_nAuthID); ReportLog(pDocEx->pChildDoc[m_nIndex], pTask, RET_REQU_SIGNIN, "终端机签到", "终端机签到--设置消费开关失败!"); pDocEx->pChildDoc[pDocEx->nPortNo]->m_nSignIn = RET_REQU_SIGNIN ; WriteLog(ErrMsg); return RET_REQU_SIGNIN; } pDocEx->pChildDoc[pDocEx->nPortNo]->m_nSignIn = 1 ; GetCurDateTime(pDocEx->pChildDoc[pDocEx->nPortNo]->m_szSignInTime); printf(ErrMsg,"-----%.8X签到成功!\n",pDocEx->pChildDoc[pDocEx->nPortNo]->m_nAuthID); ReportLog(pDocEx->pChildDoc[m_nIndex], pTask, RET_OK, "终端机签到", "终端机签到成功!"); WriteLog(ErrMsg); return RET_OK; }
long CSingInServer::ProcessSingIn(TSDeviceInfo *pDevInfo, TSSmartDoc *pDoc, TSCmdBuffer *pBuffer) { bool bResult = false; CTime tm; int E_number; unsigned char Clock[7]; unsigned char Plain[256],ID[4]; E_number = 1; //下传时钟 for(int i=0; i<3; i++) { tm=CTime::GetCurrentTime(); Clock[0] = tm.GetYear()-2000; Clock[1] = tm.GetMonth(); Clock[2] = tm.GetDay(); Clock[3] = tm.GetHour(); Clock[4] = tm.GetMinute(); Clock[5] = tm.GetSecond(); Clock[6] = tm.GetDayOfWeek(); MakeBuf_SetClock(pDevInfo, pBuffer, Clock); pBuffer->nTimeOut1 = 300;//1000 ; pBuffer->nTimeOut2 = 1000; if(SendRequest(pDoc, pBuffer) == RET_OK ) { if(UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2]) { bResult = true; break; } } Sleep(200); } if( !bResult ) { printf("终端机签到--校对时钟失败!.\n"); ReportLog(pDoc, m_pTask, RET_CLOCK_ERROR, "终端机签到", "终端机签到--校对时钟失败!"); return RET_CLOCK_ERROR; } char szKeyBuf[256]; memset(Plain, 0, sizeof(Plain)); memset(szKeyBuf, 0, sizeof(szKeyBuf)); GetAuthKey(szKeyBuf); SVC_DSP_2_HEX((unsigned char *)szKeyBuf, Plain, strlen(szKeyBuf)/2); Sleep(200); //设置授权信息 bResult = false; for(i=0; i<3; i++) { SVC_DSP_2_HEX((unsigned char *)pDoc->m_szDeviceID, ID, 4); //modified by lina 20050308 SmartEncrypt(E_number,ID,Plain); MakeBuf_SetWorkingKey(pDevInfo, pBuffer, Plain, E_number); pBuffer->nTimeOut1 = 300 ; pBuffer->nTimeOut2 = 1000; //bResult = true;//debug 20050311 if(SendRequest(pDoc, pBuffer) == RET_OK ) { if(UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] ) { bResult = true; break; } } Sleep(200); } if( !bResult ) { printf("终端机签到--设置授权信息失败!.\n"); ReportLog(pDoc, m_pTask, RET_NOT_AUTH, "终端机签到", "终端机签到--设置授权信息失败!"); return RET_NOT_AUTH; } //设置消费开关 bResult = false; Sleep(200); for(i=0; i<3; i++) { MakeBuf_SetComsumeFlag(pDevInfo, pBuffer, 1); pBuffer->nTimeOut1 = 300;//1000 ; pBuffer->nTimeOut2 = 1000; if( SendRequest(pDoc, pBuffer) == RET_OK ) { //debug 20050311 // ReportLog(pDoc, m_pTask, RET_REQU_SIGNIN, "终端机签到", "RETOK!"); if( UnMakeDeviceBuffer(pBuffer) == RET_OK&& !pBuffer->pBuffer[2] ) { bResult = true; break; } } Sleep(200); } if( !bResult ) { printf("终端机签到失败!\n"); ReportLog(pDoc, m_pTask, RET_REQU_SIGNIN, "终端机签到", "终端机签到--设置消费开关失败!"); return RET_REQU_SIGNIN; } if( SignIn && pDoc->m_nSignIn != 1 ) { SignIn(pDoc); } pDoc->m_nSignIn = 1 ; GetCurDateTime(pDoc->m_szSignInTime); ReportLog(pDoc, m_pTask, RET_OK, "终端机签到", ""); return RET_OK; }
int main() { int n = -1; int flag = 0; int flag1; int save; struct Node * head; char fileName[20] = "0"; flag = SignIn(); //登陆 if(flag == 1) { head = InitLink(); //初始化 } for(;;) //各种功能 一直循环 { fflush(stdin); flag = 1; ReturnDesk(); system("clear"); ShowDesk(); fflush(stdin); scanf("%d", &n); fflush(stdin); if(n == 0) { system("clear"); FreeAllNodes(head); printf("\n\n\n\n\n\n 谢谢使用, ----made by Mr.Du 丶Lun\n\n\n\n\n\n"); getch(); exit(0); }//if if(n == 1) { system("clear"); Print(head); }//if if(n == 4) { system("clear"); head = Sort(head); printf("sort over,new info:\n\n\n"); Print(head); } if(n == 5) { system("clear"); Print(head); Insert(head); system("clear"); printf("insert over\n"); Print(head); } if(n == 6) { system("clear"); Print(head); Remove(&head); system("clear"); printf("remove over new info:\n"); Print(head); } if(n == 8) { system("clear"); Print(head); head =AddNodeBefore(head); } if(n == 9) { system("clear"); Print(head); AddNodeAfter(head); } if(n == 10) { system("clear"); printf("倒序排列为:\n"); head = Reverse(head); Print(head); } if(n == 11) { system("clear"); if(flag1 == -1) { Save_now_info(head, fileName); save = 1; } else { //printf("%d", flag); save = Save_info(head); } if(save == 1) printf("保存成功"); } if(n == 12) { system("clear"); head = Read_info(fileName); flag1 = -1; printf("\n"); Print(head); } if(n == 2) { system("clear"); Print(head); continueCreat(head); } if(n == 13) { system("clear"); ChangePasswd(); } if(n == 3) { system("clear"); flag1 = 1; head = creatNewList(); } if(n == 7) { system("clear"); ChangeScore(head); } }//死循环 getch(); }//main
//void newProcessForClient(int conn_fd, struct sockaddr_in serv_addr, struct OnlineUser * userlist) void newPthreadForClient(int * conn_fd) { char buf[500]; char recvfrom[10]; char message[500]; char sendto[10]; int i, j; int stat; int CONN_FD; struct UserInfo user; struct Package package; int send_to_fd; char oder[20]; CONN_FD = *conn_fd; printf("##server : now is newProcessForClient \n##Waiting for Log in\n"); printf("##server : conn_fd : %d\n", CONN_FD); if(recv(CONN_FD, &user,sizeof(user), 0) == 0) { pthread_exit(0); } printf("##server : received %d\n", user.flag); printf("##server : received %s\n", user.name); printf("##server : received %s\n", user.passwd); if(user.flag == 1) { //登陆 signIn stat = SignIn(CONN_FD,user); printf("stat = %d\n", stat); if(stat == 1) { AddUser(user.name,CONN_FD); ShowUser(); send(CONN_FD, &stat, sizeof(stat), 0); } else { send(CONN_FD, &stat, sizeof(stat), 0); pthread_exit(0); } } if(user.flag == 2) { //注册signUp SignUp(CONN_FD, user); pthread_exit(0); } // strcpy(recvfrom , user.name); OnLineHint(user.name); while(1) { //解析信息 printf("##server : waitting for massage form %s\n", user.name); memset(buf, 0, sizeof(buf)); if(recv(CONN_FD, &package, sizeof(package), 0) == 0) { printf("%s off line\n", user.name); OffLine(user.name); pthread_exit(0); } //下线 if(package.order == 1 && strcmp(package.sendto, "all") == 0) { SendToAll(package); printf("now is send all\n"); continue; } send_to_fd = find_fd(package.sendto); if(package.order == 1) { if(send_to_fd == -1) { continue; } if(send(send_to_fd, &package, sizeof(package), 0) == 0) { printf("send error\n"); continue; } } if(package.order == 2) { if(strcmp(package.message, "show") == 0) { ShowOnlineUser(CONN_FD); } } } }