void LoginState::init(std::shared_ptr<Connection> connection) { GameState::init(connection); Sender::Send("Welcome to SkelMUD!\r\nPlease enter your username\r\n", connection); connection->SetPrompt(GetPrompt(connection)); int connection_id = connection->GetID(); if(m_state_map.find(connection_id) == m_state_map.end()) m_state_map[connection_id] = USERNAME; }
size_t CommandLine::DrawPrompt() { const auto PromptList = GetPrompt(); const size_t MaxLength = PromptSize*ObjWidth() / 100; std::vector<size_t> Sizes; Sizes.reserve(PromptList.size()); size_t PromptLength = 0; size_t FixedLength = 0; size_t CollapsibleCount = 0; for (const auto& i: PromptList) { Sizes.emplace_back(i.Text.size()); PromptLength += i.Text.size(); if (i.Collapsible) ++CollapsibleCount; else FixedLength += i.Text.size(); } size_t CollapsibleItemLength = 0; bool TryCollapse = false; if (PromptLength > MaxLength) { if (CollapsibleCount) { if (FixedLength < MaxLength) CollapsibleItemLength = (MaxLength - FixedLength) / CollapsibleCount; TryCollapse = true; } } size_t CurLength = 0; GotoXY(m_X1, m_Y1); for (const auto& i: PromptList) { auto str = i.Text; if (TryCollapse && i.Collapsible) { TruncPathStr(str, static_cast<int>(CollapsibleItemLength)); } if (CurLength + str.size() > MaxLength) TruncPathStr(str, std::max(0, static_cast<int>(MaxLength - CurLength))); SetColor(i.Colour); Text(str); CurLength += str.size(); if (CurLength >= MaxLength) break; } return CurLength; }
void Connection::UpdatePrompt() { m_dirty_prompt = false; m_send_buffer.append(GetPrompt() + Format::RESET); std::vector<char> output(m_send_buffer.begin(), m_send_buffer.end()); output.push_back('\0'); int sent = dataSocket.Send(&output[0]); if (sent == -1) { is_connected = false; } m_send_buffer.clear(); }
void Connection::FlushOutput() { if (m_send_buffer == "") return; m_dirty_prompt = false; m_send_buffer.append(GetPrompt() + Format::RESET); std::vector<char> output(m_send_buffer.begin(), m_send_buffer.end()); output.push_back('\0'); int sent = dataSocket.Send(&output[0]); if (sent == -1) { is_connected = false; } m_send_buffer.clear(); // prompt_tick = MAX_TICK + 1; }
void CommandLine::DisplayObject() { _OT(SysLog(L"[%p] CommandLine::DisplayObject()",this)); auto PromptList = GetPrompt(); size_t MaxLength = PromptSize*ObjWidth()/100; size_t CurLength = 0; GotoXY(X1,Y1); std::for_each(CONST_RANGE(PromptList, i) { SetColor(i.second); string str(i.first); if(CurLength + str.size() > MaxLength) TruncPathStr(str, std::max(0, static_cast<int>(MaxLength - CurLength))); Text(str); CurLength += str.size(); });
//end void CFileServerDlg::OnBnClickedButtonStopserver() { // TODO: 在此添加控件通知处理程序代码 if(GetPrompt(m_hWnd)) { GetDlgItem(IDC_STATIC_STATUS)->ShowWindow(SW_SHOW); if(StrCmp(gl_strLanguageId, CHINESE) == 0) SetDlgItemText(IDC_STATIC_STATUS, szStatTermiate_CH); else SetDlgItemText(IDC_STATIC_STATUS, szStatTermiate_EN); SetForegroundWindow(); return; } m_bContinue = false; //gl_SenderStop = true; gl_mapSenderStop[m_hWnd] = true; }
UINT16 CGymnasium::OpenGymnasium( DT_GYMNASIUM_CLI_INFO& stGymnasiumInfo, UINT8& bySkillNum,DT_SKILL_CLI_INFO* astSkillInfo, UINT32 adwSkillSumDoorsTribute[MAX_GYMNASIUM_SKILL_NUM] ) { CFaction* poFaction = GetFaction(); //检验门派 if (NULL == poFaction) { return ERR_OPEN_GYMNASIUM::ID_FACTION_NOT_EXITS; } DT_FACTION_PLAYER_DATA* pstData = poFaction->GetDT_Faction_Player_Data(m_poOwner->GetID()); if (NULL == pstData) { return ERR_OPEN_GYMNASIUM::ID_FACTION_NOT_EXITS; } BOOL bRet = IsOpen(); if (!bRet) { return ERR_OPEN_GYMNASIUM::ID_GYMNASIUM_NOT_EXIST; } //赋值武堂等级 GetGymnasiumInfo(stGymnasiumInfo); //武堂开放 if ( 0 == stGymnasiumInfo.byGymnasiumLevel) { return ERR_OPEN_GYMNASIUM::ID_GYMNASIUM_NOT_EXIST; } //赋值技能信息 GetSkillInfo(bySkillNum, astSkillInfo, adwSkillSumDoorsTribute); if ( ESM_YES == pstData->byNewSkillFlag) { //新技能提示去除 pstData->byNewSkillFlag = ESM_NO; //发送提示推送 PKT_CLIGS_FACTION_PROMPT_NTF stNtf; memset(&stNtf, 0, sizeof(PKT_CLIGS_FACTION_PROMPT_NTF)); GetPrompt(stNtf.stFactionPrompt); m_poOwner->SendMsg((TCHAR*)&stNtf, CLIGS_FACTION_PROMPT_NTF); } return ERR_OPEN_GYMNASIUM::ID_SUCCESS; }
void PromptInterpreter(Closure_clp self) { Nash_clp nash; char *buf; int nread; int leave; Rd_clp raw_in, cooked_rd; Wr_clp raw_out, cooked_wr; CLine_clp cline; CLineCtl_clp clinectl; /* Cook the command line */ raw_in = Pvs(in); raw_out = Pvs(out); leave = 0; cline = NAME_FIND("modules>CLine", CLine_clp); cooked_rd = CLine$New(cline, Pvs(in) , Pvs(out), &cooked_wr, &clinectl); Pvs(in) = cooked_rd; Pvs(out) = cooked_wr; buf = malloc(sizeof(char)*256); nash = NewNash(0); #ifdef CONFIG_NASHLOGIN while (!leave) { printf("\n\nWelcome to %s's Nemesis\n\n%s login: "******"conf>userid", string_t), gethostname()); nread = Rd$GetLine(Pvs(in), buf, 255); if (nread) buf[nread-1] = 0; if (!strcmp(buf, "reboot")) { printf("Rebooting\n"); Nash$ExecuteString(nash, "reboot"); } if (!strcmp(buf, "b") || !strcmp(buf, "boot")) { printf("Rebooting\n"); Nash$ExecuteString(nash, "b"); } if (!strcmp(buf, "root")) { leave = 1; } else if (!strcmp(buf, "user")) { leave = 1; } else if (strlen(buf) > 0) { { /* figure out homedirectory */ char *newhomedir; char *ptr; char *lastslash; nash_st *st = (nash_st*) (nash->st); newhomedir = malloc(strlen(st->homedir)+strlen(buf)); strcpy(newhomedir, st->homedir); ptr = newhomedir; lastslash = ptr; while (*ptr) { if (*ptr == '/') lastslash = ptr; ptr++; } lastslash++; strcpy(lastslash, buf); free(st->homedir); st->homedir = newhomedir; printf("New home directory will be %s\n", newhomedir); Nash$ExecuteString(nash, "cd ~"); leave = 1; } } } #endif /* CONFIG_NASHLOGIN */ Nash$ExecuteString(nash, "source profile.nash"); while (1) { printf("%s ", Nash$GetPrompt(nash)); nread = Rd$GetLine(Pvs(in), buf, 255); TRC(printf("\n")); if (nread) { buf[nread-1] = 0; TRC(printf("nread %d buf %s\n", nread, buf+1)); Nash$ExecuteString(nash, buf); } } }
void CFileServerDlg::OnDropFiles(HDROP hDropInfo) { // TODO: 在此添加消息处理程序代码和/或调用默认值 try { if(GetPrompt(m_hWnd)) { GetDlgItem(IDC_STATIC_STATUS)->ShowWindow(SW_SHOW); if(StrCmp(gl_strLanguageId, CHINESE) == 0) SetDlgItemText(IDC_STATIC_STATUS, szStatTermiate_CH); else SetDlgItemText(IDC_STATIC_STATUS, szStatTermiate_EN); SetForegroundWindow(); return; } CDialog::OnDropFiles(hDropInfo); if(m_bSending) { CString strMsg = _T("正等待响应或已经有文件正在传输,请稍候重试。"); if(StrCmp(gl_strLanguageId, CHINESE) == 0) strMsg = szWaiting_CH; else strMsg = szWaiting_EN; m_PromptDlg.SetMsgText(strMsg); m_PromptDlg.Show(); return; } else if(m_bReceive) { CString strMsg = _T("正等待响应或已经有文件正在传输,请稍候重试。"); if(StrCmp(gl_strLanguageId, CHINESE) == 0) strMsg = szWaiting_CH; else strMsg = szWaiting_EN; m_PromptDlg.SetMsgText(strMsg); m_PromptDlg.Show(); return; } char lpszFileName[MAX_PATH]; int nFileCount, k; nFileCount = DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); CString strPathFileName; int filecount = 0; int foldercount = 0; for(k = 0; k < nFileCount; k++) { DragQueryFile(hDropInfo, k, lpszFileName, MAX_PATH); CFileFind filefind; if(filefind.FindFile(lpszFileName)) { filefind.FindNextFile(); if(filefind.IsDirectory()) if(filefind.IsDirectory()) { foldercount ++; continue; } strPathFileName = filefind.GetFilePath(); filecount ++; } } if(filecount > 1) { CString strMsg = _T("一次只能传送单个文件。"); if(StrCmp(gl_strLanguageId, CHINESE) == 0) strMsg = szOneFileOnly_CH; else strMsg = szOneFileOnly_EN; m_PromptDlg.SetMsgText(strMsg); m_PromptDlg.Show(); m_bSending = false; return; } if(foldercount > 0) { CString strMsg = _T("不支持文件夹传输。"); if(StrCmp(gl_strLanguageId, CHINESE) == 0) strMsg = szNotFolder_CH; else strMsg = szNotFolder_EN; m_PromptDlg.SetMsgText(strMsg); m_PromptDlg.Show(); m_bSending = false; return; } BasicFileInfo info; CString strFileName = strPathFileName; strcpy_s(info.FileName, sizeof(info.FileName), strFileName); info.Size = 0; CFile file; if(file.Open(strPathFileName, CFile::modeRead)) { info.Size = file.GetLength(); file.Close(); } if (info.Size == 0) { CString strMsg = _T("不支持大小为0文件传输。"); if(StrCmp(gl_strLanguageId, CHINESE) == 0) strMsg = szNotZeroFile_CH; else strMsg = szNotZeroFile_EN; m_PromptDlg.SetMsgText(strMsg); m_PromptDlg.Show(); m_bSending = false; return; } State state; state = State::SRequestSend; SendMessage(WM_ADDLISTITEM, (WPARAM)&info, (LPARAM)&state); //this->m_strSendFileName = strPathFileName; CString strSendFilePathName = strPathFileName; int nFind = strSendFilePathName.ReverseFind('\\'); if(nFind != -1) { m_strSendPath = strSendFilePathName.Left(nFind); m_strSendFileName = strSendFilePathName.Right(strPathFileName.GetLength() - nFind - 1); } m_bSending = true; if(!SendFileRequest(strPathFileName)) { m_bSending = false; } } catch(...) { if (gl_pLogger) gl_pLogger->log_error("CFileServerDlg::OnDropFiles unknown exception."); } }
//CFileDialog Filedlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |OFN_EXPLORER, //| OFN_ALLOWMULTISELECT // "All files(*.*)|*.*||", NULL); void CFileServerDlg::OnBnClickedButtonAddfile() { // TODO: 在此添加控件通知处理程序代码 try { if (m_bAddFile) { try { try { //static CFileDialog Filedlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |OFN_EXPLORER, //| OFN_ALLOWMULTISELECT // "All files(*.*)|*.*||", NULL); if (m_pFileDlg) { if (IsWindow(m_pFileDlg->m_hWnd)) { m_pFileDlg->SetFocus(); } } } catch(...){} } catch(...){} return; } m_bAddFile = true; if(GetPrompt(m_hWnd)) { GetDlgItem(IDC_STATIC_STATUS)->ShowWindow(SW_SHOW); if(StrCmp(gl_strLanguageId, CHINESE) == 0) SetDlgItemText(IDC_STATIC_STATUS, szStatTermiate_CH); else SetDlgItemText(IDC_STATIC_STATUS, szStatTermiate_EN); SetForegroundWindow(); m_bAddFile = false; return; } CString filepath; //static CFileDialog Filedlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |OFN_EXPLORER, //| OFN_ALLOWMULTISELECT // "All files(*.*)|*.*||", NULL); DWORD MAXFILE = 4000; m_pFileDlg->m_ofn.nMaxFile = MAXFILE; char* pc = new char[MAXFILE]; m_pFileDlg->m_ofn.lpstrFile = pc; m_pFileDlg->m_ofn.lpstrFile[0] = NULL; CString strInitPath = GetLastFileDialogPath(); m_pFileDlg->m_ofn.lpstrInitialDir = strInitPath.GetBuffer(); ::SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); if(IDOK == m_pFileDlg->DoModal()) { if(m_bSending) { CString strMsg = _T("正等待响应或已经有文件正在传输,请稍候重试。"); if(StrCmp(gl_strLanguageId, CHINESE) == 0) strMsg = szWaiting_CH; else strMsg = szWaiting_EN; m_PromptDlg.SetMsgText(strMsg); m_PromptDlg.Show(); this->GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(_T("")); this->Invalidate(); m_bAddFile = false; return; } else if(m_bReceive) { CString strMsg = _T("正等待响应或已经有文件正在传输,请稍候重试。"); if(StrCmp(gl_strLanguageId, CHINESE) == 0) strMsg = szWaiting_CH; else strMsg = szWaiting_EN; m_PromptDlg.SetMsgText(strMsg); m_PromptDlg.Show(); this->GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(_T("")); this->Invalidate(); m_bAddFile = false; return; } CString strSendFilePathName = m_pFileDlg->GetPathName(); ProgramConfig pConfig; pConfig.SetConfigFileName("FileSetting.ini"); pConfig.WriteStringConfigParameter("File Setting", "LastFileDialogPath", strSendFilePathName); int nFind = strSendFilePathName.ReverseFind('\\'); if(nFind != -1) { m_strSendPath = strSendFilePathName.Left(nFind); m_strSendFileName = strSendFilePathName.Right(strSendFilePathName.GetLength() - nFind - 1); } BasicFileInfo info; CString strFileName = m_pFileDlg->GetFileName(); strcpy_s(info.FileName, sizeof(info.FileName), strSendFilePathName); info.Size = 0; CFile file; if(file.Open(m_pFileDlg->GetPathName(), CFile::modeRead)) { info.Size = file.GetLength(); file.Close(); } else { CString strMsg = _T("无法打开文件,该文件可能正被其他程序使用。无法发送文件。"); if(StrCmp(gl_strLanguageId, CHINESE) == 0) strMsg = szCannotOpenFile_CH; else strMsg = szCannotOpenFile_EN; m_PromptDlg.SetMsgText(strMsg); m_PromptDlg.Show(); m_bSending = false; m_bAddFile = false; return; } if (info.Size == 0) { CString strMsg = _T("不支持大小为0文件传输。"); if(StrCmp(gl_strLanguageId, CHINESE) == 0) strMsg = szNotZeroFile_CH; else strMsg = szNotZeroFile_EN; m_PromptDlg.SetMsgText(strMsg); m_PromptDlg.Show(); m_bSending = false; m_bAddFile = false; return; } if(!this->SendFileRequest(m_pFileDlg->GetPathName())) { m_bSending = false; m_bAddFile = false; return; } State state; state = State::SRequestSend; SendMessage(WM_ADDLISTITEM, (WPARAM)&info, (LPARAM)&state); m_bSending = true; } delete []pc; m_bAddFile = false; } catch(...) { if (gl_pLogger) gl_pLogger->log_error("CFileServerDlg::OnBnClickedButtonAddfile unknown exception."); } m_bAddFile = false; }