bool CKLBUITouchPad::init(CKLBTask* pTask, const char* funcname, bool modal) { if(funcname) setStrC(m_luaFunc, funcname); m_modal = modal; m_ctrlList.pGroup = NULL; m_ctrlList.pGrpPrev = NULL; m_ctrlList.pGrpNext = NULL; m_ctrlList.pBegin = NULL; m_ctrlList.next = NULL; m_ctrlList.bEnable = true; m_ctrlList.bExclusive = false; m_ctrlList.bWorking = false; m_ctrlList.pCallbackIF = NULL; m_ctrlList.nativeCallback = NULL; m_ctrlList.pID = NULL; if(m_modal) { m_modalStack.setModal(false); m_modalStack.push(); // modal stack に積む } bool result = regist(pTask, P_AFTER); if(!result) { KLBDELETEA(m_luaFunc); } m_execount = 0; return true; }
bool CKLBLifeCtrlTask::init(CKLBTask* pTask, u32 mode, u32 limit) { m_count = 0; m_mode = mode; m_limit = limit; return regist(pTask); }
bool CKLBUpdateZip::initScript(CLuaState& lua) { // bool res = true; int argc = lua.numArgs(); // 引数チェック if(argc < ARG_ZIPREQUIRE || argc > ARG_ZIPNUM) { return false; } const char * callbackUnzip = (argc >= ARG_ZIPUNZIP_CALLBACK) ? lua.getString(ARG_ZIPUNZIP_CALLBACK) : NULL; const char * callbackFinish = (argc >= ARG_ZIPFINISH_CALLBACK) ? lua.getString(ARG_ZIPFINISH_CALLBACK) : NULL; const char * callbackError = (argc >= ARG_ZIPERROR_CALLBACK) ? lua.getString(ARG_ZIPERROR_CALLBACK) : NULL; const char * tmp_name = lua.getString(ARG_ZIPTMPNAME); m_tmpPath = CKLBUtility::copyString(tmp_name); // Load "Update" info if any if (lockExist()) { m_eStep = S_INIT_UNZIP; m_zipEntry = 0; m_callbackZIP = CKLBUtility::copyString(callbackUnzip); m_callbackFinish = CKLBUtility::copyString(callbackFinish); m_callbackError = callbackError ? CKLBUtility::copyString(callbackError) : NULL; return regist(NULL, P_NORMAL); } else { return false; } }
InputWindow(const NEString& new_text, u fore, u back, const NEString& default_input_text = "") : Window(20, 12, 40, 5, fore, back, new_text), input(fore, back) { if(default_input_text != "") { input.history.push(default_input_text); input.history_idx = 1; input.text = default_input_text; } regist(1, &input); }
void CNet::_startMonitor(const char * path, int port) { #ifdef __linux__ CNetMonitorTData *pMonitor = new CNetMonitorTData(); char sock_path[PATH_MAX] = {0}; sprintf(sock_path, "%s/Net_%d.sock", path, port); pMonitor->init(sock_path); regist(&(pMonitor->monitor)); ThreadLib::Create(NetMonitorThread, pMonitor); #endif }
void* controler(void *t) //control the game's order. { int i, n, j; struct msgbuf msg; char buf[512], current_user_put_pokers[512], current_round_pokers[512], current_user_claim_pokers[512]; regist(); poker_gen(); poker_sender(); while(1) { memset(current_round_pokers, '\0', sizeof(current_round_pokers)); for(i = 0; i < MAXUSERNUM; i++) { printf("LOG: controler SEND \"TURN\" TO %d\n", connecter_fd[i]); write(connecter_fd[i], "TURN", strlen("TURN")); //read the real pokers msg = readmsg(); strcpy(buf, msg.mtext); printf("LOG: %d-----%s\n", msg.mtype, msg.mtext); sscanf(buf, "%*s%s", current_user_put_pokers); printf("LOG: %d CURRENT_USER_PUT_POKERS: %s\n", connecter_fd[i], current_user_put_pokers); strcat(current_round_pokers, current_user_put_pokers); printf("LOG: %d CURRENT_ROUND_POKERS: %s\n", connecter_fd[i], current_round_pokers); //read the claim pokers msg = readmsg(); strcpy(buf, msg.mtext); printf("LOG: %d-----%s\n", msg.mtype, msg.mtext); sscanf(buf, "%*s%s", current_user_claim_pokers); printf("LOG: %d CURRENT_USER_CLAIM_POKERS: %s\n", connecter_fd[i], current_user_claim_pokers); broadcast(connecter_fd[i], current_user_claim_pokers); //Judge Part judgement(i, current_round_pokers, current_user_put_pokers, current_user_claim_pokers); //Add pokers part, under consideration, add this function further. printf("%s\n", msg.mtext); if (!strcmp(msg.mtext, "OVER")) { printf("GAME OVER, THE WINNER IS %d\n", msg.mtype); break; } } } }
int main(int argc, char **argv) { func(regist()); // atexit(regist); if (argc != 2) return -1; argvv = argv; if (strcmp(argv[1], "done") == 0) { exit(0); } else if (strcmp(argv[1], "quit") == 0) { exit(1); } else { exit(2); } }
bool CKLBGenericTask::init(CKLBTask* pTask, CKLBTask::TASK_PHASE phase, const char * name_exec, const char * name_die, const char * arr_index) { m_luaFuncExec = CKLBUtility::copyString(name_exec); m_luaFuncDie = CKLBUtility::copyString(name_die); m_ArrayIndex = CKLBUtility::copyString(arr_index); if(!m_luaFuncExec || !m_luaFuncDie || !m_ArrayIndex) { KLBDELETEA(m_luaFuncExec); KLBDELETEA(m_luaFuncDie); KLBDELETEA(m_ArrayIndex); return false; } bool result = regist(pTask, phase); if(!result) { KLBDELETEA(m_luaFuncExec); KLBDELETEA(m_luaFuncDie); KLBDELETEA(m_ArrayIndex); } return result; }
bool CKLBUpdate::initScript(CLuaState& lua) { // bool res = true; int argc = lua.numArgs(); // 引数チェック if(argc < ARG_REQUIRE || argc > ARG_NUM) { return false; } const char * callbackDownload = (argc >= ARG_DOWNLOAD_CALLBACK) ? lua.getString(ARG_DOWNLOAD_CALLBACK) : NULL; const char * callbackUnzip = (argc >= ARG_UNZIP_CALLBACK) ? lua.getString(ARG_UNZIP_CALLBACK) : NULL; const char * callbackFinish = (argc >= ARG_FINISH_CALLBACK) ? lua.getString(ARG_FINISH_CALLBACK) : NULL; const char * callbackError = (argc >= ARG_ERROR_CALLBACK) ? lua.getString(ARG_ERROR_CALLBACK) : NULL; const char * zip_url; const char * zip_size; const char * tmp_name; zip_url = lua.getString(ARG_ZIPURL); zip_size = lua.getString(ARG_ZIPSIZE); // サイズは狂いがあると困るのでstringで受ける tmp_name = lua.getString(ARG_TMPNAME); m_tmpPath = CKLBUtility::copyString(tmp_name); m_zipURL = CKLBUtility::copyString(zip_url); m_zipSize = CKLBUtility::stringNum64(zip_size); m_eStep = S_INIT_DL; // Start from scratch and download m_dlSize = -1; m_zipEntry = 0; m_callbackDL = CKLBUtility::copyString(callbackDownload); m_callbackZIP = CKLBUtility::copyString(callbackUnzip); m_callbackFinish = CKLBUtility::copyString(callbackFinish); m_callbackError = callbackError ? CKLBUtility::copyString(callbackError) : NULL; return regist(NULL, P_NORMAL); }
bool CKLBUIControl::init(CKLBTask* /*pTask*/, const char* onClick, const char* onDrag) { if(onClick) m_onClick = CKLBUtility::copyString(onClick); if(onDrag) m_onDrag = CKLBUtility::copyString(onDrag); if(!m_onClick || !m_onDrag) { KLBDELETEA(m_onClick); KLBDELETEA(m_onDrag); return false; } m_bClick = false; m_bControl = false; m_usePt = 0; m_ctrlList.pGroup = NULL; m_ctrlList.pGrpPrev = NULL; m_ctrlList.pGrpNext = NULL; m_ctrlList.pBegin = NULL; m_ctrlList.next = NULL; m_ctrlList.bEnable = true; m_ctrlList.bExclusive = false; m_ctrlList.bWorking = false; m_ctrlList.pCallbackIF = NULL; m_ctrlList.nativeCallback = NULL; m_ctrlList.pID = NULL; if(regist(0, P_AFTER)) { m_modalStack.setModal(false); m_modalStack.setEnable(true); m_modalStack.push(); m_bModalEnable = true; return true; } // regist に失敗した場合 return false; }
void regist_on_button_clicked(GtkWidget* button,regist_msg* data) { printf("regist on button clicked\n"); printf("[%d]\n", data==NULL); printf("[%d]\n", data->username == NULL); const char* username=gtk_entry_get_text(GTK_ENTRY(data->username)); const char* password=gtk_entry_get_text(GTK_ENTRY(data->password)); printf("regist-ui %s %s\n", username, password); const char* rpassword=gtk_entry_get_text(GTK_ENTRY(data->rpassword)); if(strcmp(password,rpassword)!=0) { create_new_pop_window("please comfirm your password!"); return; } if(password_check(username,password)==FALSE) { return; } if(regist(username, password) == 0) { return ; } //create_new_pop_window("regist successful!"); gtk_widget_hide_all(data->fwidget); //gtk_main_quit(); gtk_widget_show_all(login_window); }
bool CKLBUIButton::init(CKLBTask* pTask, const char* funcname) { if(funcname) setStrC(m_luaFunc, funcname); m_ctrlList.pGroup = NULL; m_ctrlList.pGrpPrev = NULL; m_ctrlList.pGrpNext = NULL; m_ctrlList.pBegin = NULL; m_ctrlList.next = NULL; m_ctrlList.bEnable = true; m_ctrlList.bExclusive = false; m_ctrlList.bWorking = false; m_ctrlList.pCallbackIF = NULL; m_ctrlList.nativeCallback = NULL; m_ctrlList.pID = NULL; bool result = regist(pTask, P_AFTER); if(!result) { KLBDELETEA(m_luaFunc); } m_execount = 0; return true; }
KeySetTerminal(const NEString& new_path, type_ushort x=25, type_ushort y=4) : Terminal(new_path, NEType::NEKEY_CODESET, x, y, 31, 17, BLACK, DARKGRAY) { regist(4, &header, &names, &types, &data); }
KeySetTerminal(const KeySetTerminal& rhs) : Terminal(rhs), header(rhs.header), names(rhs.names), types(rhs.types), data(rhs.data) { regist(4, &header, &names, &types, &data); }
void dealMessage(){ while(1) { printf("---------------------------------\n" ); printf("%s\n","Please input numbers:" ); printf("%s\n","1:login" ); printf("%s\n","2:regist" ); printf("%s\n","3:send to one" ); printf("%s\n","4:send to all" ); printf("%s\n","5:print online list" ); printf("%s\n","6:quit" ); printf("%s\n","7:quit and close" ); printf("%s\n","8:delete me from database" ); printf("---------------------------------\n" ); char choose[10]; scanf("%s",choose); printf("this is choose:%s\n",choose ); if (!strcmp(choose,"1")) { if (local_log==1) { printf("%s\n","You have logined already." ); }else login(); } else if (!strcmp(choose,"2")) { regist(); } else if (!strcmp(choose,"3")) { if (local_log==0) { printf("%s\n","Login first, please!" ); }else sendMessage(choose[0]);//certain one send } else if (!strcmp(choose,"4")) { if (local_log==0) { printf("%s\n","Login first, please!" ); }else sendMessage(choose[0]);//group send } else if (!strcmp(choose,"5")) { sendMessage(choose[0]); } else if (!strcmp(choose,"6")) { if (local_log==0) { printf("%s\n","You didn't login!" ); }else { unlogin(choose[0]); } } else if (!strcmp(choose,"7")) { if (local_log==1) { unlogin(choose[0]); } exit(0); } else if (!strcmp(choose,"8")) { if (local_log==0) { printf("%s\n","You didn't login!I don't know who you are :(" ); }else { unlogin(choose[0]); } } else printf("%s\n","Input error" ); } }
VipRegister::VipRegister(QDialog *parent /* = 0 */) : QDialog(parent) { ui.setupUi(this); QObject::connect(ui.pushButtonRegister, SIGNAL(clicked()), this, SLOT(regist())); //QObject::connect(ui.pushButtonRegister, SIGNAL(clicked()), this, SLOT(close())); }
int main() { struct TuringMachine T; create(&T); regist(&T, 0, '0', 1, 'M', 'R'); regist(&T, 1, '0', 1, '0', 'R'); regist(&T, 1, '1', 1, '1', 'R'); regist(&T, 1, 'M', 2, 'M', 'L'); regist(&T, 1, 0, 2, 0, 'L'); regist(&T, 2, '1', 3, 'M', 'L'); regist(&T, 3, '1', 3, '1', 'L'); regist(&T, 3, '0', 4, '0', 'L'); regist(&T, 3, 'M', 5, 'M', 'R'); regist(&T, 4, '0', 4, '0', 'L'); regist(&T, 4, 'M', 0, 'M', 'R'); regist(&T, 5, 'M', 6, 'M', 'R'); //regist(&T, 0, '0', 0, '0', 'R'); //regist(&T, 0, '1', 1, '1', 'R'); //regist(&T, 0, 0, 3, 0, 'R'); //regist(&T, 1, '0', 0, '0', 'R'); //regist(&T, 1, '1', 2, '0', 'L'); //regist(&T, 1, 0, 3, 0, 'R'); //regist(&T, 2, '1', 3, '0', 'R'); execute(&T, "000111"); printf("\n"); execute(&T, "000111"); return 0; };
int main(int argc, char **argv) { char *notice; int sockfd, new_fd; //int socketNum[MAX_LINK]; //保存客户端连接数 int user_link[MAX_LINK]; int userfd[MAX_LINK]; //保存连接客户端的socket描述符号 char clientName[MAX_LINK][MAX_NAME]; char line[MAX_BUF]; char temp[MAX_BUF]; int userCount, i, j; unsigned int cli_len; struct sockaddr_in server_addr, client_addr;//网络地址结构体,包括端口号,IP地址 int port = 9999; //服务器端口号 int flag; char strfd[10]; //将int型的userfd 转化为 字符串 int length; //标志符,用来判断当前读写是否成功 fd_set sockset; int maxfd = -1; //用来标志当前连接的最大描述符 char *nam; //分割字符串得到姓名和密码,临时保存变量 char *pass; char *tokenPtr; //char friend[2] ; //保存 //指定端口号,创建socket /* if (argv[1]) myport = atoi(argv[1]); else myport = 9999; */ if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } bzero(&server_addr, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(port); server_addr.sin_addr.s_addr = htonl(INADDR_ANY); /* if (argv[3]) server_addr.sin_addr.s_addr = inet_addr(argv[3]); else server_addr.sin_addr.s_addr = INADDR_ANY; */ //绑定端口号 if (bind(sockfd, (struct sockaddr *) &server_addr, sizeof(struct sockaddr)) < 0) { perror("bind"); exit(1); } printf("-------------监听客户的连接------------\n"); fflush(stdout); //监听端口号 if (listen(sockfd, MAX_LINK) < 0) { perror("listen"); exit(1); } cli_len = sizeof(client_addr); for (i = 0; i < MAX_LINK; ++i) { user_link[i] = 0; clientName[i][0] = '\0'; } userCount = 0; FD_ZERO(&sockset); FD_SET(sockfd,&sockset); if (maxfd < sockfd + 1) { maxfd = sockfd + 1; } printf("------------启动聊天系统-----------\n"); fflush(stdout); while (1) { select(maxfd, &sockset, NULL, NULL, NULL); //如果该client已经连接过服务器 if (FD_ISSET(sockfd,&sockset) && (userCount = clinkNumber(user_link)) >= 0) { new_fd = accept(sockfd, (struct sockaddr*) &client_addr, &cli_len); if (new_fd < 0) { user_link[userCount] = 0; printf("%d连接失败\n", new_fd); fflush(stdout); } else { user_link[userCount] = 1; //标志端口存在 userfd[userCount] = new_fd; FD_SET(new_fd ,&sockset); //加入端口集合 if (maxfd < (new_fd + 1)) maxfd = new_fd + 1; printf("\n-------------用户进程描述符号为 %d 连接服务器------------", new_fd); fflush(stdout); } } //监听已注册的端口是否有数据发送 for (i = 0; i < MAX_LINK; ++i) { if ((user_link[i] == 1) && (FD_ISSET(userfd[i],&sockset))) { length = read(userfd[i], line, MAX_BUF); if (length == 0) //client的 socket已经关闭 { /*注销已经关闭的端口*/ printf("\n-------------%s 已经注销-----------\n", clientName[i]); fflush(stdout); user_link[i] = 0; clientName[i][0] = '\0'; FD_CLR(userfd[i],&sockset); } else if (length > 0) { strcpy(temp, line); line[length] = '\0'; temp[length] = '\0'; /*根据不同的字符串提示头进行操作*/ /*注册*/ if (line[0] == '@') { nam = strtok(temp, "@"); pass = strtok(NULL, "@"); flag = regist(nam, pass); if (flag == 1) { printf("\n注册成功\n "); fflush(stdout); notice = "1"; write(userfd[i], notice, strlen(notice)); } else { printf("\n注册失败\n "); fflush(stdout); notice = "0"; write(userfd[i], notice, strlen(notice)); } } /*登录*/ else if (line[0] == '/') { nam = strtok(temp, "/"); pass = strtok(NULL, "/"); /*检测用户名和密码是否正确*/ flag = login(nam, pass); if (flag == 1) { printf("\n在文件夹中找到\n "); fflush(stdout); notice = "1"; write(userfd[i], notice, strlen(notice)); } else { printf("\n用户名或者密码无法在文件中找到\n "); fflush(stdout); notice = "0"; write(userfd[i], notice, strlen(notice)); } //第一次进入聊天室&& (clientName[i][0] =="\0") if ((line[0] == '/')) { strcpy(clientName[i], nam); enterRoom(line, clientName[i]); } //播放XX进入聊天室,进行广播 if(flag==1){ printf("%s\n", line); fflush(stdout); } for (j = 0; j < MAX_LINK && (flag == 1); ++j) { if ((j != i) && (user_link[j] == 1)) { write(userfd[j], line, strlen(line)); } } }/*私聊*/ else if (line[0] == '#') { /*若以2个##开始的字串,表示开始进行私聊*/ if (line[1] == '#') { tokenPtr = strtok(temp, "/"); tokenPtr = strtok(NULL, "/"); strcpy(temp, tokenPtr); printf("%s\n", temp); fflush(stdout); strfd[0] = line[2]; strfd[1] = '\0'; write(atoi(strfd), temp, strlen(temp)); } /*只有一个#开始的字符串,表示第一次连接私聊 判断当前活动用户数是否为0 */ else { bzero(temp, MAX_BUF); if (userCount < 1) { write(userfd[i], "0", strlen("0")); } else { for (j = 0; j < MAX_LINK; ++j) { if ((j != i) && (user_link[j] == 1)) { sprintf(strfd, "%d", userfd[j]); strcat(temp, strfd); strcat(temp, "-->"); strcat(temp, clientName[j]); strcat(temp, "\n"); } } write(userfd[i], temp, strlen(temp)); } } } /*版面聊天*/ else { printf("%s\n",line); fflush(stdout); for (j = 0; j < MAX_LINK; ++j) { if ((j != i) && (user_link[j] == 1)) { write(userfd[j], line, strlen(line)); } } } } } }//結束数据传送的监听 //重置sockset集合 FD_ZERO(&sockset); FD_SET(sockfd,&sockset); for (i = 0; i < MAX_LINK; ++i) { if (user_link[i] == 1) { FD_SET(userfd[i],&sockset); } } } close(sockfd); return 0; }
bool CKLBPauseCtrl::init(CKLBTask* pTask, const char* pause, const char* resume) { m_callbackPause = (pause) ? CKLBUtility::copyString(pause) : NULL; m_callbackResume = (resume) ? CKLBUtility::copyString(resume) : NULL; return regist(pTask, P_NORMAL); }
InputWindow(const InputWindow& rhs) : Window(rhs), input(rhs.input) { regist(1, &input); }