#8
by fabersid » 6年前
! | メッセージ from: fabersid |
history_reset関数の不具合が未解決です。 |
参考:
コマンドプロントの閉じるボタンの無効化のやり方 by aberu » 5年前
無題 by 恐 » 8年前
#7の既読後コードを追加し強制終了されることによる
不具合が起きにくくなりました。
コード:
#define WIN32_LEAN_AND_MEAN // Windows ヘッダーから使用されていない部分を除外します。
#define LOG_DIR "DATA.{BB06C0E4-D293-4f75-8A90-CB05B6477EEE}"
#define LOG_FILE LOG_DIR"\\LOG.dll"
//define DATA FILEs
/*
DATA.{BB06C0E4-D293-4f75-8A90-CB05B6477EEE}
LOG.dll
Users
username
・
・
・
*/
#define KEY 123
#include <windows.h>
#include <sys\stat.h> //フォルダの確認(stat)
#include <direct.h> //フォルダの作成(_mkdir)
#include <string> //ヘッダファイルインクルード
#include <iostream> //標準入出力(C++)
#include <fstream> //ファイル入出力
#include <stdio.h>
#include <stdlib.h> //標準ライブラリ…system()
#include <algorithm>
using namespace std; //名前空間指定
bool user_make(const string);
bool command(const string);
bool checkFileExistence(string);
void add_file(const string);
void display_file();
void history_reset();
string ango(const string);
int main(){
string text="";
string ango;
string user;
do{
user="";
cerr << "ユーザー名を入力:";
cin >> user;
}while(!user_make(user));
struct stat statBuf;
if (stat(LOG_DIR, &statBuf) != 0){
if (_mkdir(LOG_DIR) != 0){
printf("ディレクトリを作成できませんでした。\n。");
printf("異常終了\n");
return 1;
}
}
if (stat(LOG_DIR"\\Users", &statBuf) != 0){
if (_mkdir(LOG_DIR"\\Users") != 0){
printf("ディレクトリを作成できませんでした。\n。");
printf("異常終了\n");
return 1;
}
}
const char * consoleName = "退室するときはEXITと打ってください。";
cout << consoleName;
Sleep(3000);
SetConsoleTitle(consoleName);
Sleep(50);
HWND hWnd = FindWindowA(NULL, consoleName);
if(hWnd){
HMENU hMenu = GetSystemMenu(hWnd, FALSE);
RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
SetConsoleCtrlHandler(NULL , TRUE);
}else{
// printf("%s\n", "失敗");
}
add_file(user + "さんが入室しました。");
while("EXIT"!=text){
if(text!=""){
if(!command(text)){
add_file(user+">>"+text);
}
}
display_file();
cerr << user << ">>";
history_reset();
getline(cin, text);
history_reset();
}
add_file(user + "さんが退室しました。");
return 0;
}
void add_file(string a){
if(a=="")return;
ofstream ofs(LOG_FILE,ios::binary|ios::app);
ofs << ango(a + "\r\n");
ofs.close();
}
void display_file(){
system("cls");
ifstream ifs(LOG_FILE,ios::binary);
if(!ifs){ return; } //ファイルが開けたか確認
char buf[256+1]; //256バイトと '\0 'の分のバッファ
while(!ifs.eof()){
ifs.read(buf,256); //ストリームから256バイトバッファに読み込む
buf[ifs.gcount()] = '\0';
cout << ango(buf); //標準出力に出力してみる
}
ifs.close();
}
void history_reset(){/*
ここでAlt + F7 を押し自動で入力内容の
履歴を消すはずだが動作しないのでコメント化している。
ここの部分は検索中
知っている方は教えていただきたい
#define VK_MENU 0x12/*Alt*/
#define VK_F7 0x76/*F7*/
// キーの押し下げをシミュレートする。
keybd_event( VK_MENU, 0, 0, 0);
// キーの押し下げをシミュレートする。
keybd_event( VK_F7, 0, 0, 0);
system("timeout /t 1 /NOBREAK>nul");
// キーの解放をシミュレートする。
keybd_event( VK_F7, 0, KEYEVENTF_KEYUP, 0);
// キーの解放をシミュレートする。
keybd_event( VK_MENU, 0, KEYEVENTF_KEYUP, 0);*/
}
string ango(string tmp){
string ret=tmp;
for(int i = 0; i < (int)ret.size(); ++i){
ret[i] = ret[i] ^ KEY;
}
return ret;
}
//https://qiita.com/takahiro_itazuri/items/e999ae24ab34b2756b04
#include<string>
#include<fstream>
#include<iostream>
bool checkFileExistence(string str){
str=LOG_DIR"\\Users\\"+str;
ifstream ifs(str.c_str());
return ifs.is_open();
}
bool user_make(string userName){
if(checkFileExistence(userName)){
cout << userName << "は使用済みです。";
return false;
}
string str=LOG_DIR"\\Users\\"+userName;
ofstream ofs(str.c_str());
return true;
}
bool user_delete(string userName){
if(remove((LOG_DIR"\\Users\\"+userName).c_str()) != 0 ){
fprintf(stderr,"%sは存在しません",userName.c_str());
return false;
}
return true;
}
bool command(string text){
#define cmd_exec(x,y) {if(text.substr(0,strlen(x))==x){y(text.substr(strlen(x)));return true;}}
//x=string y=function
cmd_exec("/ban ",user_delete);
cmd_exec("/help ",help);
#undef cmd_exec
return false;
}
void help(string dummy){
cout
<< "/ban ユーザー名"
<< "ユーザーをtext.exeから追放します。"
<< "/help"
<< "この画面が表示されます。"
<< "EXIT"
<< "投稿を終了します。";
}
[mod=fabersid]history_reset関数の不具合が未解決です。[/mod]
参考:[url=https://dixq.net/forum/viewtopic.php?f=3&t=10858]コマンドプロントの閉じるボタンの無効化のやり方[/url] by aberu » 5年前
[url=https://dixq.net/forum/viewtopic.php?f=3&t=3390&p=28805#p28805]無題[/url] by 恐 » 8年前
#7の既読後コードを追加し強制終了されることによる
不具合が起きにくくなりました。
[code=cpp]#define WIN32_LEAN_AND_MEAN // Windows ヘッダーから使用されていない部分を除外します。
#define LOG_DIR "DATA.{BB06C0E4-D293-4f75-8A90-CB05B6477EEE}"
#define LOG_FILE LOG_DIR"\\LOG.dll"
//define DATA FILEs
/*
DATA.{BB06C0E4-D293-4f75-8A90-CB05B6477EEE}
LOG.dll
Users
username
・
・
・
*/
#define KEY 123
#include <windows.h>
#include <sys\stat.h> //フォルダの確認(stat)
#include <direct.h> //フォルダの作成(_mkdir)
#include <string> //ヘッダファイルインクルード
#include <iostream> //標準入出力(C++)
#include <fstream> //ファイル入出力
#include <stdio.h>
#include <stdlib.h> //標準ライブラリ…system()
#include <algorithm>
using namespace std; //名前空間指定
bool user_make(const string);
bool command(const string);
bool checkFileExistence(string);
void add_file(const string);
void display_file();
void history_reset();
string ango(const string);
int main(){
string text="";
string ango;
string user;
do{
user="";
cerr << "ユーザー名を入力:";
cin >> user;
}while(!user_make(user));
struct stat statBuf;
if (stat(LOG_DIR, &statBuf) != 0){
if (_mkdir(LOG_DIR) != 0){
printf("ディレクトリを作成できませんでした。\n。");
printf("異常終了\n");
return 1;
}
}
if (stat(LOG_DIR"\\Users", &statBuf) != 0){
if (_mkdir(LOG_DIR"\\Users") != 0){
printf("ディレクトリを作成できませんでした。\n。");
printf("異常終了\n");
return 1;
}
}
const char * consoleName = "退室するときはEXITと打ってください。";
cout << consoleName;
Sleep(3000);
SetConsoleTitle(consoleName);
Sleep(50);
HWND hWnd = FindWindowA(NULL, consoleName);
if(hWnd){
HMENU hMenu = GetSystemMenu(hWnd, FALSE);
RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
SetConsoleCtrlHandler(NULL , TRUE);
}else{
// printf("%s\n", "失敗");
}
add_file(user + "さんが入室しました。");
while("EXIT"!=text){
if(text!=""){
if(!command(text)){
add_file(user+">>"+text);
}
}
display_file();
cerr << user << ">>";
history_reset();
getline(cin, text);
history_reset();
}
add_file(user + "さんが退室しました。");
return 0;
}
void add_file(string a){
if(a=="")return;
ofstream ofs(LOG_FILE,ios::binary|ios::app);
ofs << ango(a + "\r\n");
ofs.close();
}
void display_file(){
system("cls");
ifstream ifs(LOG_FILE,ios::binary);
if(!ifs){ return; } //ファイルが開けたか確認
char buf[256+1]; //256バイトと '\0 'の分のバッファ
while(!ifs.eof()){
ifs.read(buf,256); //ストリームから256バイトバッファに読み込む
buf[ifs.gcount()] = '\0';
cout << ango(buf); //標準出力に出力してみる
}
ifs.close();
}
void history_reset(){/*
ここでAlt + F7 を押し自動で入力内容の
履歴を消すはずだが動作しないのでコメント化している。
ここの部分は検索中
知っている方は教えていただきたい
#define VK_MENU 0x12/*Alt*/
#define VK_F7 0x76/*F7*/
// キーの押し下げをシミュレートする。
keybd_event( VK_MENU, 0, 0, 0);
// キーの押し下げをシミュレートする。
keybd_event( VK_F7, 0, 0, 0);
system("timeout /t 1 /NOBREAK>nul");
// キーの解放をシミュレートする。
keybd_event( VK_F7, 0, KEYEVENTF_KEYUP, 0);
// キーの解放をシミュレートする。
keybd_event( VK_MENU, 0, KEYEVENTF_KEYUP, 0);*/
}
string ango(string tmp){
string ret=tmp;
for(int i = 0; i < (int)ret.size(); ++i){
ret[i] = ret[i] ^ KEY;
}
return ret;
}
//https://qiita.com/takahiro_itazuri/items/e999ae24ab34b2756b04
#include<string>
#include<fstream>
#include<iostream>
bool checkFileExistence(string str){
str=LOG_DIR"\\Users\\"+str;
ifstream ifs(str.c_str());
return ifs.is_open();
}
bool user_make(string userName){
if(checkFileExistence(userName)){
cout << userName << "は使用済みです。";
return false;
}
string str=LOG_DIR"\\Users\\"+userName;
ofstream ofs(str.c_str());
return true;
}
bool user_delete(string userName){
if(remove((LOG_DIR"\\Users\\"+userName).c_str()) != 0 ){
fprintf(stderr,"%sは存在しません",userName.c_str());
return false;
}
return true;
}
bool command(string text){
#define cmd_exec(x,y) {if(text.substr(0,strlen(x))==x){y(text.substr(strlen(x)));return true;}}
//x=string y=function
cmd_exec("/ban ",user_delete);
cmd_exec("/help ",help);
#undef cmd_exec
return false;
}
void help(string dummy){
cout
<< "/ban ユーザー名"
<< "ユーザーをtext.exeから追放します。"
<< "/help"
<< "この画面が表示されます。"
<< "EXIT"
<< "投稿を終了します。";
}[/code]