客户端:
对于系统退出:SYS_KILL_NET
void Window::checkRight()
{
double tmp_hours = ceil(GlobalData::authon->start_time.secsTo(QDateTime::currentDateTime()))/(3600*1.0);
double tmp_cost = GlobalData::authon->remain_cost - tmp_hours * GlobalData::authon->base_cost;
switch( GlobalData::authon->usertype )
{
case 1:
{
if( tmp_cost < 0 )
{
sysQuit();
MessageBoxs * msg = new MessageBoxs(NULL,3);
msg->setInfo(tr("温馨提示"),tr("尊敬的用户,金额已用完,您已被迫断网,请续缴网费后重新登陆.")+QString(
"<p><img src = ':/icons/warn.png' width = 12 height = 12/>"
"<a href=\"http://www.seaares.com\">"
"<span style=\" text-decoration: underline; color:#0000ff;\">"
"www.seaares.com</a></p>"));
msg->exec();
qApp->quit();
}
}
break;
case 2:
{
if( GlobalData::authon->remain_flow - nowData.up_flow <= 0 )
{
sysQuit();
MessageBoxs * msg = new MessageBoxs(NULL,3);
msg->setInfo(tr("温馨提示"),tr("尊敬的用户,流量已用完,您已被迫断网,请购买流量后重新登陆.")+QString(
"<p><img src = ':/icons/warn.png' width = 12 height = 12/>"
"<a href=\"http://www.seaares.com\">"
"<span style=\" text-decoration: underline; color:#0000ff;\">"
"www.seaares.com</a></p>"));
msg->exec();
qApp->quit();
}
}
break;
case 3:
{
if( tmp_cost < 0 )
{
if( GlobalData::authon->remain_flow > 0 )
{
QMessageBox::StandardButton rb;
rb = QMessageBox::information(NULL, QObject::tr("温馨提示"),
QObject::tr("金额已用完,是否切换为流量用户?"),
QMessageBox::Yes | QMessageBox::No);
if(QMessageBox::Yes == rb)
{
RMessage_CHANGE_USER_ROLE userRole;
userRole.id = GlobalData::authon->userid;
userRole.usertype = GlobalData::authon->usertype;
userRole.service_type = GlobalData::authon->service_type;
userRole.base_cost = GlobalData::authon->base_cost;
userRole.stime = GlobalData::authon->start_time;
if( checkFirst )
userRole.consumption = 0;
else
userRole.consumption = tmp_hours * userRole.base_cost;
GlobalData::link->changeUserRole(userRole);
return;
}
}
sysQuit();
MessageBoxs * msg = new MessageBoxs(NULL,3);
msg->setInfo(tr("温馨提示"),tr("尊敬的用户,金额已用完,您已被迫断网.<br/>请切换为流量用户或充值后重新登陆.")+QString(
"<p><img src = ':/icons/warn.png' width = 12 height = 12/>"
"<a href=\"http://www.seaares.com\">"
"<span style=\" text-decoration: underline; color:#0000ff;\">"
"www.seaares.com</a></p>"));
msg->exec();
qApp->quit();
}
else
{
if( GlobalData::authon->remain_flow < 0 &&
GlobalData::authon->service_type > 0 )
{
sysQuit();
MessageBoxs * msg = new MessageBoxs(NULL,3);
msg->setInfo(tr("温馨提示"),tr("尊敬的用户,此服务需要流量,但流量不足,您已被迫断网,请续缴网费或购买流量后重新登陆.")+QString(
"<p><img src = ':/icons/warn.png' width = 12 height = 12/>"
"<a href=\"http://www.seaares.com\">"
"<span style=\" text-decoration: underline; color:#0000ff;\">"
"www.seaares.com</a></p>"));
msg->exec();
qApp->quit();
}
}
}
break;
case 4:
{
if( GlobalData::authon->validtime <= QDateTime::currentDateTime() )
{
sysQuit();
MessageBoxs * msg = new MessageBoxs(NULL,3);
msg->setInfo(tr("温馨提示"),tr("尊敬的用户,包时间期限已到,您已被迫断网,请续缴网费后重新登陆.")+QString(
"<p><img src = ':/icons/warn.png' width = 12 height = 12/>"
"<a href=\"http://www.seaares.com\">"
"<span style=\" text-decoration: underline; color:#0000ff;\">"
"www.seaares.com</a></p>"));
msg->exec();
qApp->quit();
}
}
break;
default:
break;
}
}
void Window::sysQuit()
{
reconnectTimer->stop();
CheckRight->stop();
AuthonHeartTimer->stop();
heartTimer->stop();
foreach(Chatroom* room, *GlobalData::FndChat)
room->close();
GlobalData::FndChat->clear();
RMessage_CHANGE_STATUS status;
status.SS_Id = GlobalData::myself->Id;
status.SS_UserStatus = OFFLINE;
GlobalData::link->quitRequest(status);
RMessage_USER_QUIT_AUTHON authon(SYS_KILL_NET);
authon.userid = GlobalData::myself->Id;
// getflow(authon.up_flow,authon.down_flow);
authon.usertype = GlobalData::authon->usertype;
authon.start_time = GlobalData::authon->start_time;
authon.service_type = GlobalData::authon->service_type;
if( checkFirst )
{
authon.base_cost = 0;
}
else
{
if( GlobalData::authon->usertype == 1 )
authon.base_cost = GlobalData::authon->base_cost;
else if( GlobalData::authon->usertype == 2 )
authon.base_cost = 0;
else if( GlobalData::authon->usertype == 3 )
authon.base_cost = GlobalData::authon->base_cost;
}
GlobalData::link->SysKillNet(authon);
CheckRight->stop();
AuthonHeartTimer->stop();
// QProcess p1(NULL);
// p1.start("setProxy_r.exe", QStringList()<<GlobalData::proxyIp<<"80"<<GlobalData::myself->Id<<(GlobalData::authon->Password) << "0");
// p1.waitForStarted();
// p1.waitForFinished();
// p1.close();
// setHttpProxy hp;
// hp.m_proxyEnable = false;
// hp.setIEValue();
// if( !hp.checkHttpProxy() )
// qDebug() << tr("%1:代理设置失败!").arg(Q_FUNC_INFO);
// hp.close();
}
服务器端:
系统退出:SYS_KILL_NET
qint32 MysqlPool::authonSysQuitRequest(MessageBase* save)
{
QDateTime ttt = QDateTime::currentDateTime();
Sqlhelper help;
if(!help.succ())
return DB_ERROR;
RMessage_USER_QUIT_AUTHON *temp = dynamic_cast<RMessage_USER_QUIT_AUTHON*>(save);
PreparedStatement* psmt = NULL;
//geng xin qian
if( temp->base_cost != 0 )
{
qDebug() << temp->userid << temp->usertype;
psmt = help.getpst("update Onnetuser set Onnetuser_etime = ?,"
"Onnetuser_ctime = TIMESTAMPDIFF(HOUR,?,Onnetuser_stime) + 1,Onnetuser_consumption = "
"((TIMESTAMPDIFF(HOUR,?,Onnetuser_stime)+1 )* ?) where Onnetuser_user = ? and UserType_id = ? "
"and Onnetuser_stime = ? and Onnetuser_etime is NULL;");
psmt->setDateTime(1,qPrintable(ttt.toString("yyyy-MM-dd hh:mm:ss")));
psmt->setDateTime(2,qPrintable(ttt.toString("yyyy-MM-dd hh:mm:ss")));
psmt->setDateTime(3,qPrintable(ttt.toString("yyyy-MM-dd hh:mm:ss")));
psmt->setDouble(4,temp->base_cost);
psmt->setString(5,qPrintable(temp->userid));
psmt->setInt(6,temp->usertype);
psmt->setDateTime(7,qPrintable(temp->start_time.toString("yyyy-MM-dd hh:mm:ss")));
}
else
{
qDebug() << temp->userid << temp->usertype;
psmt = help.getpst("update Onnetuser set Onnetuser_etime = ? "
"where Onnetuser_user = ? and UserType_id = ? and Onnetuser_stime = ? and Onnetuser_etime is NULL;");
psmt->setDateTime(1,qPrintable(ttt.toString("yyyy-MM-dd hh:mm:ss")));
psmt->setString(2,qPrintable(temp->userid));
psmt->setInt(3,temp->usertype);
psmt->setDateTime(4,qPrintable(temp->start_time.toString("yyyy-MM-dd hh:mm:ss")));
}
int i = psmt ->executeUpdate();
if(i > 0)
{
PreparedStatement* psmt2 = help.getpst(" delete from Authon where user = ?;");
psmt2->setString(1,qPrintable(temp->userid));
int i2 = psmt2 ->executeUpdate();
if(i2 > 0)
{
qDebug() << "yong hu yi tui chu";
return SYS_KILL_NET_SUCCEED;
}
}
else
return SYS_KILL_NET_FAILED;
}
用户退出:USER_KILL_NET
qint32 MysqlPool::authonQuitRequest(MessageBase* save)
{
QDateTime ttt = QDateTime::currentDateTime();
Sqlhelper help;
if(!help.succ())
return DB_ERROR;
RMessage_USER_QUIT_AUTHON *temp = dynamic_cast<RMessage_USER_QUIT_AUTHON*>(save);
PreparedStatement* psmt = NULL;
//geng xin qian
if( temp->base_cost != 0 )
{
qDebug() << temp->userid << temp->usertype;
psmt = help.getpst("update Onnetuser set Onnetuser_etime = ?,"
"Onnetuser_ctime = TIMESTAMPDIFF(HOUR,?,Onnetuser_stime) + 1,Onnetuser_consumption = "
"((TIMESTAMPDIFF(HOUR,?,Onnetuser_stime)+1 )* ?) where Onnetuser_user = ? and UserType_id = ? "
"and Onnetuser_stime = ? and Onnetuser_etime is NULL;");
psmt->setDateTime(1,qPrintable(ttt.toString("yyyy-MM-dd hh:mm:ss")));
psmt->setDateTime(2,qPrintable(ttt.toString("yyyy-MM-dd hh:mm:ss")));
psmt->setDateTime(3,qPrintable(ttt.toString("yyyy-MM-dd hh:mm:ss")));
psmt->setDouble(4,temp->base_cost);
psmt->setString(5,qPrintable(temp->userid));
psmt->setInt(6,temp->usertype);
psmt->setDateTime(7,qPrintable(temp->start_time.toString("yyyy-MM-dd hh:mm:ss")));
}
else
{
qDebug() << temp->userid << temp->usertype;
psmt = help.getpst("update Onnetuser set Onnetuser_etime = ? "
"where Onnetuser_user = ? and UserType_id = ? and Onnetuser_stime = ? and Onnetuser_etime is NULL;");
psmt->setDateTime(1,qPrintable(ttt.toString("yyyy-MM-dd hh:mm:ss")));
psmt->setString(2,qPrintable(temp->userid));
psmt->setInt(3,temp->usertype);
psmt->setDateTime(4,qPrintable(temp->start_time.toString("yyyy-MM-dd hh:mm:ss")));
}
int i = psmt ->executeUpdate();
if(i > 0)
{
PreparedStatement* psmt2 = help.getpst("delete from Authon where user = ?;");
psmt2->setString(1,qPrintable(temp->userid));
int i2 = psmt2 ->executeUpdate();
if(i2 > 0)
{
qDebug() << "yong hu yi tui chu";
return USER_KILL_NET_SUCCEED;
}
}
else
return USER_KILL_NET_FAILED;
}