📄 chatdll.cpp
字号:
//功能描述:保存点数
//参数说明:UserInfo 当前用户的数据
// bExit 为是否退出功能调用
CString SavePoint(ChatUserInfoTag &UserInfo, bool bExit)
{
CString strResult, strCmd;
long nNowTime = time(NULL);
long nCount = (nNowTime - UserInfo.nLoginTime); //在线时间
long nJiFen = nCount / 60;
CDatabase db;
try{
if( nJiFen > 0 ){
if(db.OpenEx( strDatabase )){
strCmd.Format("update basic_tbl set jifen=jifen+%ld where uin=%lu and chat=%s", nJiFen, UserInfo.nID, UserInfo.strRnd);
db.ExecuteSQL( strCmd );
if(bExit)
strResult = "";
else{
nJiFen += UserInfo.nSays;
strCmd.Format("你在聊天室中%ld秒,对话%ld句,增加积分%ld点。", nCount, UserInfo.nSays, nJiFen);
strResult = MakeSay( "blue", "存点", "", "", UserInfo.strUserName, strCmd, "", "");
}
UserInfo.nLoginTime = nNowTime;
UserInfo.nSays = 0;
}else{
if(bExit)
strResult = "";
else
strResult = MakeSay( "red", "提示", "", "", UserInfo.strUserName, "连接数据库未成功。", "", "");
}
}else{
if(bExit)
strResult = "";
else
strResult = MakeSay( "Red", "提示", "", "", UserInfo.strUserName, "每次存点必须间隔一分钟时间。", "", "");
}
}catch(...){
if(bExit)
strResult = "";
else
strResult = MakeSay( "Red", "错误", "", "", UserInfo.strUserName, "在调用存点程序时出现内部错误。", "", "");
}
return strResult;
}
//---------------------------------------------------------------------------
//功能描述: 取用户状态
//参数说明: UserInfo 为当前用户信息
//返 回 值: 返回用户状态
CString GetState(ChatUserInfoTag &UserInfo)
{
CString strSex[3] = {"保密", "男", "女"};
CString strResult, strTemp;
strResult = "<B> 我的状态</B><BR>" + Table();
strTemp.Format("<TD>TT号: %lu<TD>昵称: %s<TD>来自: %s", UserInfo.nID, UserInfo.strNick, UserInfo.strFrom);
strResult += TR2() + strTemp;
strTemp.Format("<TD>性别: %s<TD>隐身: %s<TD>头像: %s", strSex[UserInfo.nSex], UserInfo.bHidden ? "是" : "否", UserInfo.bShowIcon ? "开" : "关");
strResult += TR2() + strTemp;
strTemp.Format("<TD>对话: %ld 句<td>在线: %ld 秒<TD>等级: %ld 级", UserInfo.nSays, time(NULL) - UserInfo.nLoginTime, UserInfo.nLevel);
strResult += TR2() + strTemp;
strResult += "</table>";
return strResult;
}
//---------------------------------------------------------------------------
//功能描述: 取得SOCKET 的 IP 地址
//参数说明: UserInfo1 为当前用户的信息
// UserInfo2 为被看方的用户信息
//返 回 值: 返回取IP的结果
CString GetIP(ChatUserInfoTag &UserInfo1, ChatUserInfoTag &UserInfo2)
{
CString strResult;
if(UserInfo1.nLevel >= UserInfo2.nLevel){
if(UserInfo2.Socket == NULL)
strResult = "%2已经断开与服务器的连接.";
else{
CString strAddr;
unsigned int nPort;
UserInfo2.Socket->GetPeerName(strAddr, nPort);
strAddr = strAddr.Left(strAddr.ReverseFind('.') + 1) + "*";
strResult = "%2的IP地址为: " + strAddr;
}
}else
strResult = "你的等级不大于对方的等级, 不能查看对方IP";
return strResult;
}
//---------------------------------------------------------------------------
//功能描述: 由 OnTimer2() 调用的生成聊天室信息文件的函数
//参数说明: UserInfo[] 聊天室所有人的信息
// nMaxUser 聊天室最大人数
// RoomInfo 聊天室信息
void MakeInfoFile(ChatUserInfoTag *UserInfo, int nMaxUser, ChatRoomInfoTag *RoomInfo)
{
/* FILE *fp;
CString str, strFile;
str.Format("document.write('%ld');\r\n", RoomInfo->nUserCount);
strFile.Format("%s\\%d.js", RoomInfo->strRoot, RoomInfo->nPort);
fp = fopen(strFile, "w+");
if( fp ){
fprintf(fp, str);
}
fclose(fp);*/
/*
int i;
TStringList *S = new TStringList;
String O;
try{
O = "var Room" + ROOM + " = new Array('--" + RoomName + "--'";
for(i = 0; i < DMaxUser; i ++)
if(User[i].Name != "" && !User[i].Hidden)
O = O + ",'" + User[i].Name + "'";
O = O + ");ShowUser(Room" + ROOM + ");";
S->Text = O;
S->SaveToFile(WWWDIR + ROOM + ".js");
}
__finally{
delete S;
}*/
}
//---------------------------------------------------------------------------
//功能描述: 包间操作
//参数说明: UserInfo 当前用户的信息
// RoomInfo 当前聊天室的信息
// strResult 回返的内容
// *nSendType 返回内容的发送方式
void HireRoom(ChatUserInfoTag &UserInfo, ChatRoomInfoTag *RoomInfo, CString &strResult, int *nSendType)
{
CString strCmd;
CDatabase db;
CDBVariant NV;
CRecordset rs(&db);
try{
if(db.OpenEx( strDatabase )){
strCmd.Format("select * from basic_tbl where uin=%lu and chat=%s", UserInfo.nID, UserInfo.strRnd);
rs.Open( AFX_DB_USE_DEFAULT_TYPE, strCmd);
if( !rs.IsEOF() ){
rs.GetFieldValue( "jifen", NV );
if( NV.m_lVal < RoomInfo->nHireRoom )
strResult = MakeSay( "red", "提示", UserInfo.strUserName, "", "", "你的积分不够包间", "", "");
else{
strCmd.Format("update basic_tbl set jifen=jifen-%ld where uin=%lu and chat=%s", RoomInfo->nHireRoom, UserInfo.nID, UserInfo.strRnd);
db.ExecuteSQL( strCmd );
CString str;
str.Format("|%lu|", UserInfo.nID);
strcpy(RoomInfo->strAdminList, str);
strResult = MakeSay ("red", "包间", UserInfo.strUserName, "", "", "%1成功地包下了本聊天室", "", "");
*nSendType = 2;
}
}else
strResult = MakeSay ("red", "提法", UserInfo.strUserName, "", "", "你未正常登录或该聊天室重复登录其他室", "", "");
}
}catch(...){
strResult = MakeSay( "red", "错误", UserInfo.strUserName, "", "", "调用包间程序时出现异常错误", "", "");
}
}
//---------------------------------------------------------------------------
//功能描述:聊天室管理功能
//参数说明: nPos 为发言用户在 UserInfo[] 中的成员号
// *B, *C 为命令参数
// *D 为命令对象
// *nSendType 为发送返回内容的类型,0为对自己(默认),1为两人,2为所有人,3为所有室
// UserInfo[] 为聊天室人员的数据
// nMaxUser 为聊天室的最大人数
// *PowerAdminList 为聊天站高级管理员ID列表
// RoomInfo 为本室的一些数据
void Manage(int nPos, CString *B, CString *C, CString *D, int *nSendType, ChatUserInfoTag *UserInfo, int nMaxUser, CString *PowerAdminList, ChatRoomInfoTag *RoomInfo, CString &strResult){
int ndx, nPos1;
CString strTemp, strAdminList;
strTemp.Format("|%lu|", UserInfo[nPos].nID);
strAdminList.Format("%s", RoomInfo->strAdminList);
ndx = PowerAdminList->Find( strTemp );
if( ndx == -1 )
ndx = strAdminList.Find(strTemp);
else
ndx = -2; //高级管理员
if( ndx == -1 )
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", "", "你不是本室的管理员,不能使用该命令", "", "");
else{
if( *B == "警告" ){
strResult = MakeSay( "red", "警告", UserInfo[nPos].strUserName, "", *D, "<B>%1对%2警告道: " + *C + "</B>", "", "");
*nSendType = 2;
}
else if( *B == "踢人" ){
nPos1 = GetID( *D, UserInfo, nMaxUser);
if(nPos1 < nMaxUser){
strTemp.Format("|%lu|", UserInfo[nPos1].nID);
int ndx1 = PowerAdminList->Find( strTemp );
if( ndx == -1 )
ndx1 = strAdminList.Find(strTemp);
else
ndx1 = -2; //高级管理员
if(ndx1 == -1 || ndx < ndx1){
strResult = MakeSay( "blue", "踢出", UserInfo[nPos].strUserName, "", UserInfo[nPos1].strUserName, "%2被%1踢出了聊天室,原因:" + *C, "", "");
strTemp.Format("<script>parent.DelUser('%s')</script>", UserInfo[nPos1].strUserName);
strResult += strTemp;
UserInfo[nPos1].Socket->Send(strResult, strResult.GetLength());
InitUser(nPos1, UserInfo);
*nSendType = 2;
}else
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", UserInfo[nPos1].strUserName, "%2的权限比你更大,你不能踢他。", "", "");
}else
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", *D, "%2不在线,无法使用该命令。", "", "");
}
else if( *B == "主题" || *B == "话题" ){
if( ndx < 1 ){
ndx = (*C).GetLength();
if( ndx > 0 && ndx < 255 ){
strResult = MakeSay( "red", *B, UserInfo[nPos].strUserName, "", "", "室长[%1]将本室的话题设置为:" + *C, "", "");
strcpy( RoomInfo->strTopic, *C );
*nSendType = 2;
}else
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", "", "输入的话题太长了, 请确定长度为 1 - 250 之间", "", "");
}else
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", "", "只有本室的主人或高级管理员才可以设置本室话题", "", "");
}
else if( *B == "房名" ){
if( ndx < 1 ){
nPos1 = (*C).GetLength();
if( nPos1 > 0 && nPos1 < 21 ){
if( ndx == 0 )
strTemp.Format( "%%2把房间[%s]改名为[%d.%s]。", RoomInfo->strRoomName, RoomInfo->nRoomNo, *C );
else
strTemp.Format( "%%2把房间[%s]改名为[%s]。", RoomInfo->strRoomName, *C );
strResult = MakeSay( "blue", "房名", "", "", UserInfo[nPos].strUserName, strTemp, "", "" );
if( ndx == 0 )
sprintf( RoomInfo->strRoomName, "%d.%s", RoomInfo->nRoomNo, *C );
else
strcpy( RoomInfo->strRoomName, *C );
strTemp.Format( "<script>parent.RoomData[%d]='%s';parent.UserList();</script>", RoomInfo->nRoomNo, RoomInfo->strRoomName );
strResult += strTemp;
}else
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", "", "输入的房间名称太长了, 请确定长度在 1 - 20 之间", "", "");
}else
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", "", "只有本室的主人或高级管理员才可以设置本室名称", "", "");
}
else if( *B == "添加" ){
if( ndx < 1 ){
strTemp.Format("|%s|", *C);
if( strAdminList.GetLength() + strTemp.GetLength() > 250 )
strResult = MakeSay("red", "提示", UserInfo[nPos].strUserName, "", "", "本室的管理人员已经满员,不能再增加了。", "", "" );
else{
ndx = strAdminList.Find(strTemp);
if( ndx == -1 ){
sprintf( RoomInfo->strAdminList, "%s%s|", strAdminList, *C );
strResult = MakeSay("blue", "管理", UserInfo[nPos].strUserName, "", *C, "TT号%2被%1添加为本室管理员", "", "");
*nSendType = 2;
}else
strResult = MakeSay("red", "提示", UserInfo[nPos].strUserName, "", *C, "TT号%2已经是本室的管理员了,请不要重复添加", "", "");
}
}else
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", "", "只有本室的主人或高级管理员才有此权力", "", "");
}
else if( *B == "解除" ){
if( ndx < 1 ){
strTemp.Format("|%s|", *C);
ndx = strAdminList.Find( strTemp );
if( ndx == -1 )
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", *C, "TT号%2并不是本室的管理员", "", "" );
else{
strAdminList.Replace( strTemp, "|" );
strcpy( RoomInfo->strAdminList, strAdminList );
strResult = MakeSay( "blue", "管理", UserInfo[nPos].strUserName, "", *C, "TT号%2被%1解除了本室管理员权力", "", "");
*nSendType = 2;
}
}else
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", "", "只有本室的主人或高级管理员才有此权力", "", "");
}
else
strResult = MakeSay( "red", "提示", UserInfo[nPos].strUserName, "", "", "非法的命令参数", "", "");
}
}
//---------------------------------------------------------------------------
//功能描述: 在线用户名单
//参数说明: UserInfo[] 为聊天室所有人员的数据
// nMaxUser 为聊天室最大的人数
// RoomInfo 为聊天室信息
// strBody 为返回的内容
void OnlineUsers(ChatUserInfoTag *UserInfo, int nMaxUser, ChatRoomInfoTag *RoomInfo, CString &strBody)
{
CString str;
int ndx;
// str.Format("var roomInfo = new Array('%s','%s');\r\n", RoomInfo->strRoomName, RoomInfo->strTopic);
strBody = "var userlist = new Array(";
for( ndx = 0; ndx < nMaxUser; ndx ++ ){
if( UserInfo[ndx].nID != 0 ){
str.Format("'%s[%lu]',%d,'%s',", UserInfo[ndx].strNick, UserInfo[ndx].nID, UserInfo[ndx].nSex, UserInfo[ndx].strResume);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -