exeing score.cpp
2025/2/10
#include <bits/stdc++.h>
#include <windows.h>
#include <time.h>
using namespace std;
string preIP = "172.18.10.";
string MSGcmd = "msg /server ";
map < string, string > users =
{
// eg: {"38", "gzxworld"},{...},...
};
double Sleep_time = 500;
string myusername = "Momo";
string return_msg = "return";
void cerr_time()
{
time_t nowtime;
struct tm* p;
time(&nowtime);
p = localtime(&nowtime);
cerr << '[' << p -> tm_hour << ':' << p -> tm_min << ':' << p -> tm_sec << "] ";
}
void preWork(string &x)
{
x = myusername + ": " + x;
for (int i = 0 ; i < (int)x.size() ; i ++)
{
if(x[i] == '\"')
{
x[i] = '\'';
}
}
x = '"' + x + '"';
}
void work(string x, int times)
{
if (times > 20)
{
cout << "You should be enough friendly...\n";
cout << times << "<--" << 20 << '\n';
times = 20;
}
while (times --)
{
system(x.c_str());
cout << "done.\n";
cerr_time();
cerr << x << " done.\n";
Sleep(Sleep_time);
}
}
string get_command(string user, string messg)
{
return MSGcmd + preIP + user + " * " + messg;
}
void MainPaint()
{
system("cls");
cout << "ChatPro\n\n";
for (auto i : users)
{
cout << i.first << ' ' << i.second << '\n';
}
cout << "Input IP to enter > ";
}
pair < int, string > solvetimes(string x)
{
string nums, newx;
int i = 0;
while (!isdigit(x[i]))
{
i ++;
}
while(isdigit(x[i]))
{
nums += x[i];
i ++;
}
for (int j = i ; j < (int)x.size() ; j ++)
{
newx += x[j];
}
// cerr << nums << '\n';
int res = 0;
int e = 1;
for (int j = nums.size() - 1 ; j >= 0 ; j --)
{
res += (nums[j] - '0') * e;
e *= 10;
}
return {res, newx};
}
bool check_if_IP(string &x)
{
// cerr << "check " << x;
if ((int)x.size() > 2)
{
// cerr << "0\n";
return false;
}
for (int i = 0 ; i < (int)x.size() ; i ++)
{
if (!(x[i] >= '0' and x[i] <= '9'))
{
// cerr << "0\n";
return false;
}
}
// cerr << "1\n";
return true;
}
int mesg_order(string mesg, string &toIP)
{
// cerr << "order: recive " << mesg << " toIP = " << toIP << '\n';
int times = 1;
if (mesg[0] == '/')
{
string command_string;
int k = 0;
for (int i = 1 ; i < (int)mesg.size() ; i ++)
{
if (mesg[i] == ' ')
{
k = i;
break;
}
command_string += mesg[i];
}
mesg.erase(0, k + 1);
// cerr << "mesg ->" << mesg << '\n';
if (command_string == "share")
{
string recognize_IP;
vector < string > IP_list;
int las = - 1;
k = 0;
for (int i = 0 ; i < (int)mesg.size() ; i ++)
{
if (mesg[i] == ' ')
{
if (check_if_IP(recognize_IP) == false)
{
las = k;
k = i;
break;
}
else
{
las = k;
k = i;
IP_list.push_back(recognize_IP);
recognize_IP.clear();
}
}
else
{
recognize_IP += mesg[i];
}
}
mesg.erase(0, las + 1);
for (auto i : IP_list)
{
if (users.count(i) == false)
{
cout << "Error : ";
cout << "Your input is " << i << '\n';
Sleep(2000);
continue;
}
mesg_order(mesg, i);
}
}
else
{
cout << "Error : Command " << "'" << command_string << "'" << " not recognized\n";
return 0;
}
return 1;
}
if (mesg[0] == '.' and mesg[1] == '%')
{
auto res = solvetimes(mesg);
times = res.first;
mesg = res.second;
preWork(mesg);
work(get_command(toIP, mesg), times);
}
else
{
preWork(mesg);
work(get_command(toIP, mesg), times);
}
return times;
}
void chat(string toIP)
{
system("cls");
if(users.count(toIP) == false)
{
cout << "Error\n";
cout << "Your input is" << toIP << '\n';
Sleep(200);
return;
}
cout << users[toIP] << ": \n\n\n[please input \"" << return_msg << "\" to cancel]\n\n";
int cnt = 1;
getchar();
while (true)
{
cout << cnt << '.' << myusername << " > ";
string mesg;
// getchar();
getline(cin, mesg);
if(mesg == return_msg)
{
return;
}
// 总控
mesg = mesg + ' ';
int times = mesg_order(mesg, toIP);
cnt += times;
cout << "\n\n";
}
}
void importData()
{
freopen("data.txt", "r", stdin);
string opt;
while(cin >> opt)
{
if (opt == "UserName")
{
cin >> myusername;
cerr_time();
cerr << "UserName was Loaded\n";
}
else if (opt == "SleepTime")
{
cin >> Sleep_time;
cerr_time();
cerr << "Sleep_time was Loaded\n";
}
else if (opt == "Objects")
{
string Numb;
while (cin >> Numb)
{
if (Numb == "0")
{
break;
}
string Name;
cin >> Name;
users.insert({Numb, Name});
cerr_time();
cerr << "Import Object " << Numb << ' ' << Name << '\n';
}
}
else if (opt == "ReturnMsg")
{
cin >> return_msg;
cerr_time();
cerr << "ReturnMsg was loaded\n";
}
else if (opt == "PreIP")
{
cin >> preIP;
cerr_time();
cerr << "PreIP was loaded\n";
}
Sleep(10);
}
// fclose(stdin);
return;
}
signed main()
{
freopen("log.log", "a", stderr);
cerr << "-------------------------------------\n";
cout << "Loading...";
importData();
Sleep(50);
freopen("CON", "r", stdin);
cin.clear();
while (true)
{
MainPaint();
string x;
cin >> x;
chat(x);
// Sleep(1000);
}
return 0;
}
2025/2/24
Update : 消息效果预览指令
#include <bits/stdc++.h>
#include <windows.h>
#include <time.h>
using namespace std;
namespace init
{
map < string, string > users =
{
// eg: {"38", "gzxworld"},{...},...
};
string preIP = "172.18.10.";
string MSGcmd = "msg /server ";
double Sleep_time = 500;
string myusername = "Momo";
string return_msg = "return";
string my_ip = "xx";
}
void cerr_time()
{
time_t nowtime;
struct tm* p;
time(&nowtime);
p = localtime(&nowtime);
cerr << '[' << p -> tm_hour << ':' << p -> tm_min << ':' << p -> tm_sec << "] ";
}
void preWork(string &x)
{
x = init :: myusername + ": " + x;
for (int i = 0 ; i < (int)x.size() ; i ++)
{
if(x[i] == '\"')
{
x[i] = '\'';
}
}
x = '"' + x + '"';
}
void work(string x, int times)
{
if (times > 20)
{
cout << "You should be enough friendly...\n";
cout << times << "<--" << 20 << '\n';
times = 20;
}
while (times --)
{
system(x.c_str());
cout << "done.\n";
cerr_time();
cerr << x << " done.\n";
Sleep(init :: Sleep_time);
}
}
string get_command(string user, string messg)
{
return init :: MSGcmd + init :: preIP + user + " * " + messg;
}
void MainPaint()
{
system("cls");
cout << "ChatPro\n\n";
for (auto i : init :: users)
{
cout << i.first << ' ' << i.second << '\n';
}
cout << "Input IP to enter > ";
}
pair < int, string > solvetimes(string x)
{
string nums, newx;
int i = 0;
while (!isdigit(x[i]))
{
i ++;
}
while(isdigit(x[i]))
{
nums += x[i];
i ++;
}
for (int j = i ; j < (int)x.size() ; j ++)
{
newx += x[j];
}
// cerr << nums << '\n';
int res = 0;
int e = 1;
for (int j = nums.size() - 1 ; j >= 0 ; j --)
{
res += (nums[j] - '0') * e;
e *= 10;
}
return {res, newx};
}
bool check_if_IP(string &x)
{
// cerr << "check " << x;
if ((int)x.size() > 2)
{
// cerr << "0\n";
return false;
}
for (int i = 0 ; i < (int)x.size() ; i ++)
{
if (!(x[i] >= '0' and x[i] <= '9'))
{
// cerr << "0\n";
return false;
}
}
// cerr << "1\n";
return true;
}
int mesg_order(string mesg, string &toIP)
{
// cerr << "order: recive " << mesg << " toIP = " << toIP << '\n';
int times = 1;
if (mesg[0] == '/')
{
string command_string;
int k = 0;
for (int i = 1 ; i < (int)mesg.size() ; i ++)
{
if (mesg[i] == ' ')
{
k = i;
break;
}
command_string += mesg[i];
}
mesg.erase(0, k + 1);
// cerr << "mesg ->" << mesg << '\n';
if (command_string == "share")
{
string recognize_IP;
vector < string > IP_list;
int las = - 1;
k = 0;
for (int i = 0 ; i < (int)mesg.size() ; i ++)
{
if (mesg[i] == ' ')
{
if (check_if_IP(recognize_IP) == false)
{
las = k;
k = i;
break;
}
else
{
las = k;
k = i;
IP_list.push_back(recognize_IP);
recognize_IP.clear();
}
}
else
{
recognize_IP += mesg[i];
}
}
mesg.erase(0, las + 1);
for (auto i : IP_list)
{
if (init :: users.count(i) == false)
{
cout << "Error : ";
cout << "Your input is " << i << '\n';
Sleep(2000);
continue;
}
mesg_order(mesg, i);
}
}
else if (command_string == "preview")
{
preWork(mesg);
mesg = "Preview: " + mesg;
work(get_command(init :: my_ip, mesg), 1);
}
else
{
cout << "Error : Command " << "'" << command_string << "'" << " not recognized\n";
return 0;
}
return 1;
}
if (mesg[0] == '.' and mesg[1] == '%')
{
auto res = solvetimes(mesg);
times = res.first;
mesg = res.second;
preWork(mesg);
work(get_command(toIP, mesg), times);
}
else
{
preWork(mesg);
work(get_command(toIP, mesg), times);
}
return times;
}
void chat(string toIP)
{
system("cls");
if (init :: users.count(toIP) == false)
{
cout << "Error\n";
cout << "Your input is " << toIP << '\n';
Sleep(600);
return;
}
cout << init :: users[toIP] << ": \n\n\n[please input \"" << init :: return_msg << "\" to cancel]\n\n";
int cnt = 1;
getchar();
while (true)
{
cout << cnt << '.' << init :: myusername << " > ";
string mesg;
// getchar();
getline(cin, mesg);
if(mesg == init :: return_msg)
{
return;
}
// 总控
mesg = mesg + ' ';
int times = mesg_order(mesg, toIP);
cnt += times;
cout << "\n\n";
}
}
void importData()
{
freopen("data.txt", "r", stdin);
string opt;
while(cin >> opt)
{
if (opt == "UserName")
{
cin >> init :: myusername;
cerr_time();
cerr << "UserName " << init :: myusername << " was Loaded\n";
}
else if (opt == "SleepTime")
{
cin >> init :: Sleep_time;
cerr_time();
cerr << "Sleep_time " << init :: Sleep_time << " was Loaded\n";
}
else if (opt == "Objects")
{
string Numb;
while (cin >> Numb)
{
if (Numb == "0")
{
break;
}
string Name;
cin >> Name;
init :: users.insert(make_pair(Numb, Name));
cerr_time();
cerr << "Import Object " << Numb << ' ' << Name << '\n';
}
}
else if (opt == "ReturnMsg")
{
cin >> init :: return_msg;
cerr_time();
cerr << "ReturnMsg " << init :: return_msg << " was loaded\n";
}
else if (opt == "PreIP")
{
cin >> init :: preIP;
cerr_time();
cerr << "PreIP " << init :: preIP << " was loaded\n";
}
else if (opt == "MyIP")
{
cin >> init :: my_ip;
cerr_time();
cerr << "MyIP " << init :: my_ip << " was loaded\n";
}
else
{
cout << "\nError :\ndata.txt error\n";
cerr_time();
cerr << "------- [Import Error] -------\n";
Sleep(5000);
return;
}
Sleep(10);
}
// fclose(stdin);
return;
}
signed main()
{
freopen("log.log", "a", stderr);
cerr << "-------------------------------------\n";
cout << "Loading...";
importData();
Sleep(50);
freopen("CON", "r", stdin);
cin.clear();
while (true)
{
MainPaint();
string x;
cin >> x;
chat(x);
// Sleep(1000);
}
return 0;
}

浙公网安备 33010602011771号