当前位置:首页>>魔兽单机>>正文
魔兽单机:一个答题系统的代码(供参考使用)
2013-07-05 17:12:15 作者:网络 来源: 浏览次数:0
摘要:一个答题系统的代码
 Index: src/game/World.cpp
 
===================================================================
 
--- src/game/World.cpp (revision 6247)
 
+++ src/game/World.cpp (working copy)
 
@@ -53,7 +53,8 @@
 
 #include "WorldSocket.h"
 #include "GridNotifiersImpl.h"
 #include "CellImpl.h"
-
+#include  <stdlib.h>    
+#include  <stdio.h>  
 INSTANTIATE_SINGLETON_1( World );
 
 volatile bool World::m_stopEvent = false;
@@ -885,7 +886,10 @@
 
         local.tm_year+1900, local.tm_mon+1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
 
     WorldDatabase.PExecute("INSERT INTO uptime (startstring, starttime, uptime) VALUES('%s', %ld, 0)", isoDate, m_startTime );
-
+    static uint32 messageauto = 0;
+    static uint32 question = 0;
+    messageauto= sConfig.GetIntDefault("Message.Auto", 30000);
+    question= sConfig.GetIntDefault("Message.Question", 10000);
     m_timers[WUPDATE_OBJECTS].SetInterval(0);
     m_timers[WUPDATE_SESSIONS].SetInterval(0);
     m_timers[WUPDATE_WEATHERS].SetInterval(1000);
@@ -893,7 +897,9 @@
 
     m_timers[WUPDATE_UPTIME].SetInterval(m_configs[CONFIG_UPTIME_UPDATE]*MINUTE*1000);
                                                             //Update "uptime" table based on configuration entry in minutes.
     m_timers[WUPDATE_CORPSES].SetInterval(20*MINUTE*1000);  //erase corpses every 20 minutes
-
+ m_timers[WUPDATE_MESSAGEAUTO].SetInterval(messageauto);
+ m_timers[WUPDATE_QUESTION].SetInterval(question);
+    m_timers[WUPDATE_JIAREN].SetInterval(10000);
     //to set mailtimer to return mails every day between 4 and 5 am
     //mailtimer is increased when updating auctions
     //one second is 1000 -(tested on win system)
@@ -1115,7 +1121,21 @@
 
         m_timers[WUPDATE_EVENTS].SetInterval(nextGameEvent);
         m_timers[WUPDATE_EVENTS].Reset();
     }
-
+        if (m_timers[WUPDATE_MESSAGEAUTO].Passed())
+    {
+        m_timers[WUPDATE_MESSAGEAUTO].Reset();
+                SendRNDBroadcast();
+    }
+        if (m_timers[WUPDATE_QUESTION].Passed())
+    {
+        m_timers[WUPDATE_QUESTION].Reset();
+                showquestion();
+    }
+         if (m_timers[WUPDATE_JIAREN].Passed())
+    {
+        m_timers[WUPDATE_JIAREN].Reset();
+                refreshjiaren();
+    }
     /// </ul>
     ///- Move all creatures with "delayed move" and remove and delete all objects with "delayed remove"
     ObjectAccessor::Instance().DoDelayedMovesAndRemoves();
@@ -2178,3 +2198,129 @@
 
     m_maxActiveSessionCount = std::max(m_maxActiveSessionCount,uint32(m_sessions.size()-m_QueuedPlayer.size()));
     m_maxQueuedSessionCount = std::max(m_maxQueuedSessionCount,uint32(m_QueuedPlayer.size()));
 }
+
+
+void World::SendRNDBroadcast()
+{
+    std::string msg;
+    QueryResult *result = WorldDatabase.PQuery("SELECT `nr` FROM `autosend` ORDER BY RAND() LIMIT 1");
+                if(!result)
+                        return;
+        msg = result->Fetch()[0].GetString();
+        delete result;
+ msg = "[|cffff0000 公告|r]:"+msg;
+    //   static uint32 messageautoinf = 0;
+    //messageautoinf = sConfig.GetIntDefault("Message.Auto.inf", 0);
+    //if(messageautoinf == 0)
+    //{
+        sWorld.SendWorldText(msg.c_str(), NULL);
+    //    }
+    //    if(messageautoinf == 1)
+    //    {
+    //    WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
+    //    data << str;
+    //    sWorld.SendGlobalMessage(&data);
+    //    }
+    //   sLog.outString(msg.c_str());
+}
+
+void World::showquestion()
+{
+    std::string msg;
+ std::string aa;
+ std::string bb;
+ std::string cc;
+ std::string dd;
+ uint32 fl;
+ QueryResult *result0 = WorldDatabase.PQuery("SELECT * FROM autoquestion where flag=1");//
+ if(result0)
+ {
+ sWorld.SendWorldText("上道题太难以至于没人答出", NULL);
+ WorldDatabase.PExecute("update autoquestion set flag=0");
+ }
+ delete result0;
+        QueryResult *result = WorldDatabase.PQuery("SELECT nr,a,b,c,d,id FROM autoquestion ORDER BY RAND() LIMIT 1");//?漴??
+        if(!result)
+ {sLog.outString("没有找到题目");
+ return;}
+        msg = result->Fetch()[0].GetString();
+ aa = result->Fetch()[1].GetString();
+ bb = result->Fetch()[2].GetString();
+ cc = result->Fetch()[3].GetString();
+ dd = result->Fetch()[4].GetString();
+ fl = result->Fetch()[5].GetUInt32();
+                delete result;
+        msg = "[|cffff0000 提问|r]:"+msg;
+    msg = msg +" A:"+aa+" B:"+bb+" C:"+cc+" D:"+dd;
+ sWorld.SendWorldText(msg.c_str(), NULL);
+        WorldDatabase.PExecute("update autoquestion set flag=1 where id='%d'",fl);
+//        sLog.outString(msg.c_str());
+}
+
+void World::refreshjiaren()
+{
+ //   //float t = sConfig.GetFloatDefault("RATE.JIAREN",1);
+ //   uint32 zrs;
+ //   uint32 jiaren;
+ //   uint32 accid;
+ //   uint32 nameid;
+ //   std::string pname;
+ //   QueryResult *result3 = loginDatabase.PQuery("SELECT id FROM account where online=1");
+ //   zrs= result3->GetRowCount();
+ //   //jiaren = (int)(t*zrs+0.5);
+ //jiaren = 2;
+ //   QueryResult *result = loginDatabase.PQuery("SELECT id FROM account where online=0  ORDER BY RAND() LIMIT 4");
+ //   //QueryResult *result4 = loginDatabase.PQuery("SELECT id FROM account where online=0");
+
+ //   if(!result)
+ //       return;
+ ////   do
+ ////   {
+ ////accid = result4->Fetch()[0].GetUInt32();
+ ////       //CharacterDatabase.PExecute("update characters set online=0 where account='%d'",accid);
+ ////}while( result4->NextRow() );
+ //   do
+ //   {
+ //    accid = result->Fetch()[0].GetUInt32();
+ //       
+ //       //CharacterDatabase.PExecute("update characters set online=1 where account='%d' ORDER BY RAND() LIMIT 1",accid);
+ //       QueryResult *result4 = CharacterDatabase.PQuery("select guid,name from characters where account='%d' ORDER BY RAND() LIMIT 1",accid);
+ //       nameid = result4->Fetch()[0].GetUInt32();
+ //       pname = result4->Fetch()[1].GetCppString();
+ //       normalizePlayerName(pname);
+ //       Player* pchr = objmgr.GetPlayer(pname.c_str());
+ //       sLog.outString("already create");
+ //       float x,y,z,o;
+ //       uint32 map;
+ //       bool in_flight;
+ //       pchr->LoadPositionFromDB(map,x,y,z,o,in_flight,objmgr.GetPlayerGUIDByName(pname));
+ //       sLog.outString("already load");
+ //       MapManager::Instance().GetMap(pchr->GetMapId(), pchr)->Add(pchr);
+ //       ObjectAccessor::Instance().AddObject(pchr);
+ //       sLog.outString("successfully");
+ //}while( result->NextRow() );
+ //delete result;
+ //   delete result3;
+}
+
+
+    uint32 accid;
+    uint32 nameid;
+    std::string pname;
+    QueryResult *result4;
+    QueryResult *result3 = loginDatabase.PQuery("SELECT id FROM account where online=1");
+    zrs= result3->GetRowCount();
+    QueryResult *result = loginDatabase.PQuery("SELECT id FROM account where online=0  ORDER BY RAND() LIMIT 4");
+    if(!result)
+        return;
+    do
+    {
+    accid = result->Fetch()[0].GetUInt32();
+        result4 = CharacterDatabase.PQuery("select guid,name from characters where account='%d' ORDER BY RAND() LIMIT 1",accid);
+        nameid = result4->Fetch()[0].GetUInt32();
+        pname = result4->Fetch()[1].GetCppString();
+
+ }while( result->NextRow() );
+ delete result;
+    delete result3;
+    delete result4;
 
\ No newline at end of file
 


相关报道:

[关闭] [返回顶部]


  返回首页 | 最新资讯 | 资源下载 | 魔兽图片 | 单机文档 | 技术攻略 | 玩家视频
备案号:蜀ICP备2024062380号-1
免责声明:本网站为热爱怀旧WOW的玩家们建立的魔兽世界资料网站,仅供交流和学习使用,非盈利和商用.如有侵权之处,请联系我们,我们会在24小时内确认删除侵权内容,谢谢合作。
Copyright © 2024 - 2024 WOWAII.COM Corporation, All Rights Reserved

机器人国度