Advertisement
newsgames

SendFunc.cpp

Apr 12th, 2020
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 46.99 KB | None | 0 0
  1. #include <memory>
  2. #include "..\Basedef.h"
  3. #include "SendFunc.h"
  4. #include "GetFunc.h"
  5. #include "Server.h"
  6. #include "Language.h"
  7.  
  8. void SendClientMsg(int conn, char *Message)
  9. {
  10.     if (conn <= 0 || conn >= MAX_USER)
  11.         return;
  12.  
  13.     MSG_MessagePanel sm_mp;
  14.     memset(&sm_mp, 0, sizeof(MSG_MessagePanel));
  15.  
  16.     sm_mp.Size = sizeof(MSG_MessagePanel);
  17.     sm_mp.Type = _MSG_MessagePanel;
  18.     sm_mp.ID = 0;
  19.  
  20.     memcpy(sm_mp.String, Message, MESSAGE_LENGTH);
  21.  
  22.     sm_mp.String[MESSAGE_LENGTH - 1] = 0;
  23.     sm_mp.String[MESSAGE_LENGTH - 2] = 0;
  24.  
  25.     pUser[conn].cSock.AddMessage((char*)&sm_mp, sizeof(MSG_MessagePanel));
  26. }
  27.  
  28. void SendRecycle(int conn)
  29. {
  30.     if (pUser[conn].Mode != USER_PLAY) return;
  31.  
  32.     MSG_Recycle m;
  33.     memset(&m, 0, sizeof(MSG_Recycle));
  34.     m.ID = conn;
  35.     m.Type = 0x3E8;
  36.     m.Size = sizeof(MSG_Recycle);
  37.  
  38.     for (int i = 0; i < _Max_Recycle_Bin_; i++)
  39.     {
  40.         m.Recycle[i] = pMob[conn].Recycle[i];
  41.     }
  42.  
  43.     if (!pUser[conn].cSock.AddMessage((char*)&m, sizeof(MSG_Recycle)))
  44.         CloseUser(conn);
  45. }
  46.  
  47.  
  48. void SendQuest(int conn)
  49. {
  50.     STRUCT_QUESTDIARIA packet;
  51.     memset(&packet, 0, sizeof(STRUCT_QUESTDIARIA));
  52.  
  53.     packet.Type = 0xD08;
  54.     packet.ID = conn;
  55.     packet.Size = sizeof(STRUCT_QUESTDIARIA);
  56.  
  57.     packet.Count1 = pUser[conn].CountMob1;
  58.     packet.Count2 = pUser[conn].CountMob2;
  59.     packet.Count3 = pUser[conn].CountMob3;
  60.  
  61.     packet.CountMax1 = QuestDiaria[pUser[conn].QuestAtiva].QtdMob1;
  62.     packet.CountMax2 = QuestDiaria[pUser[conn].QuestAtiva].QtdMob2;
  63.     packet.CountMax3 = QuestDiaria[pUser[conn].QuestAtiva].QtdMob3;
  64.  
  65.     packet.QtdItem = QuestDiaria[pUser[conn].QuestAtiva].Item->stEffect[0].cValue;
  66.     packet.ExpReward = QuestDiaria[pUser[conn].QuestAtiva].ExpReward;
  67.     packet.GoldReward = QuestDiaria[pUser[conn].QuestAtiva].GoldReward;
  68.  
  69.     packet.IndexQuest = pUser[conn].QuestAtiva;
  70.  
  71.     pUser[conn].cSock.SendOneMessage((char*)&packet, sizeof(STRUCT_QUESTDIARIA));
  72.  
  73. }
  74.  
  75. void SendClientPac(int conn)
  76. {
  77.     STRUCT_CLIENTPAC packet;
  78.     memset(&packet, 0, sizeof(STRUCT_CLIENTPAC));
  79.  
  80.     int value = 0;
  81.     packet.Type = 0xD02;
  82.     packet.ID = conn;
  83.     packet.Size = sizeof(STRUCT_CLIENTPAC);
  84.  
  85.     if(pMob[conn].MOB.Clan == 7)
  86.     packet.Points[0] = value++;
  87.  
  88.     if (pMob[conn].MOB.Clan == 8)
  89.         packet.Points[1] = value++;
  90.  
  91.  
  92.     pUser[conn].cSock.SendOneMessage((char*)&packet, sizeof(STRUCT_CLIENTPAC));
  93.  
  94. }
  95.  
  96. bool SendSaveBanned(int conn)
  97. {
  98.     if (conn < 0 || conn > MAX_USER)
  99.         return false;
  100.  
  101.     std::ofstream outputFile(strFmt("Ban/%s.bin", pUser[conn].AccountName), std::ofstream::out | std::ofstream::binary);
  102.  
  103.     if (outputFile.is_open())
  104.     {
  105.         AccountBanned temp;
  106.         std::memcpy(&temp, &BannedUser[conn], sizeof(AccountBanned));
  107.  
  108.         outputFile.write(reinterpret_cast<char*>(&BannedUser[conn]), sizeof(AccountBanned));
  109.         outputFile.close();
  110.         return true;
  111.     }
  112.  
  113.     return false;
  114.  
  115.  
  116. }
  117.  
  118. void SendNotice(char *Message)
  119. {
  120.     char Notice[512];
  121.  
  122.     sprintf(Notice, "not %s", Message);
  123.     Log(Notice, "-system", NULL);
  124.  
  125.     if (Message[0] == '\'' && Message[1] == 'x')
  126.         return;
  127.  
  128.     for (int i = 0; i < MAX_USER; i++)
  129.     {
  130.         if (pUser[i].Mode == USER_PLAY)
  131.             SendClientMsg(i, Message);
  132.     }
  133. }
  134.  
  135. void SendNoticeChief(char *Message)
  136. {
  137.     char Notice[512];
  138.  
  139.     sprintf(Notice, "not %s", Message);
  140.  
  141.     Log(Notice, "-system", NULL);
  142.  
  143.     for (int i = 0; i < MAX_USER; i++)
  144.     {
  145.         if (pUser[i].Mode != USER_PLAY)
  146.             continue;
  147.  
  148.         if (pMob[i].MOB.GuildLevel != 9)
  149.             continue;
  150.  
  151.         int Guild = pMob[i].MOB.Guild;
  152.  
  153.         if (Guild <= 0)
  154.             continue;
  155.  
  156.         int FoundCharged = 0;
  157.  
  158.         for (int j = 0; j < MAX_SERVER; j++)
  159.         {
  160.             for (int k = 0; k < MAX_GUILDZONE; k++)
  161.             {
  162.                 if (ChargedGuildList[j][k] && ChargedGuildList[j][k] == Guild)
  163.                 {
  164.                     FoundCharged = 1;
  165.                     break;
  166.                 }
  167.             }
  168.         }
  169.  
  170.         SendClientMsg(i, Message);
  171.     }
  172. }
  173.  
  174. void SendSummonChief()
  175. {
  176.     Log("summon chief", "-system", NULL);
  177.  
  178.     for (int i = 0; i < MAX_USER; i++)
  179.     {
  180.         if (pUser[i].Mode != USER_PLAY)
  181.             continue;
  182.  
  183.         if (pMob[i].MOB.GuildLevel != 9)
  184.             continue;
  185.  
  186.         int Guild = pMob[i].MOB.Guild;
  187.  
  188.         if (Guild <= 0)
  189.             continue;
  190.  
  191.         int FoundCharged = 0;
  192.  
  193.         int Server = 0;
  194.         int GuildZone = 0;
  195.  
  196.         for (int j = 0; j < MAX_SERVER; j++)
  197.         {
  198.             for (int k = 0; k < MAX_GUILDZONE; k++)
  199.             {
  200.                 if (ChargedGuildList[j][k] && ChargedGuildList[j][k] == Guild)
  201.                 {
  202.                     FoundCharged = 1;
  203.                     Server = j;
  204.                     GuildZone = k;
  205.  
  206.                     break;
  207.                 }
  208.             }
  209.         }
  210.  
  211.         if (FoundCharged == 0)
  212.             return;
  213.  
  214.         int tx = 7 * Server / 5 + 317;
  215.         int ty = 4025 - 2 * Server % 5;
  216.  
  217.         if (Server / 5)
  218.             tx = tx + GuildZone;
  219.         else
  220.             tx = tx - GuildZone;
  221.  
  222.         DoTeleport(i, tx, ty);
  223.     }
  224. }
  225.  
  226. void SendNoticeArea(char *Message, int x1, int y1, int x2, int y2)
  227. {
  228.     for (int i = 0; i < MAX_USER; i++)
  229.     {
  230.         if (pUser[i].Mode != USER_PLAY)
  231.             continue;
  232.  
  233.         if (pMob[i].TargetX >= x1 && pMob[i].TargetX <= x2 && pMob[i].TargetY >= y1 && pMob[i].TargetY <= y2)
  234.             SendClientMsg(i, Message);
  235.     }
  236. }
  237.  
  238. void SendGuildNotice(int Guild, char *Message)
  239. {
  240.     for (int i = 0; i < MAX_USER; i++)
  241.     {
  242.         if (pUser[i].Mode == USER_PLAY)
  243.         {
  244.             if (pMob[i].MOB.Guild == Guild)
  245.                 SendClientMsg(i, Message);
  246.         }
  247.     }
  248. }
  249.  
  250. void SendClientMessageOk(int conn, char *Message, int Useless1, int Useless2) //Useless
  251. {
  252.     if (conn <= 0 || conn >= MAX_USER)
  253.         return;
  254.  
  255.     MSG_MessageBoxOk sm_mbo;
  256.     memset(&sm_mbo, 0, sizeof(MSG_MessageBoxOk));
  257.  
  258.     sm_mbo.Type = _MSG_MessageBoxOk;
  259.  
  260.     memcpy(sm_mbo.String, Message, MESSAGE_LENGTH);
  261.  
  262.     sm_mbo.Useless1 = Useless1;
  263.     sm_mbo.Useless2 = Useless2;
  264.  
  265.     pUser[conn].cSock.AddMessage((char*)&sm_mbo, sizeof(MSG_MessageBoxOk));
  266. }
  267.  
  268.  
  269. void SendClientSignal(int conn, int id, unsigned short signal)
  270. {
  271.     MSG_STANDARD sm;
  272.     memset(&sm, 0, sizeof(MSG_STANDARD));
  273.  
  274.     sm.Type = signal;
  275.     sm.ID = id;
  276.  
  277.     pUser[conn].cSock.AddMessage((char*)&sm, sizeof(sm));
  278. }
  279.  
  280. void SendClientSignalParm(int conn, int id, unsigned short signal, int parm)
  281. {
  282.     MSG_STANDARDPARM sm;
  283.     memset(&sm, 0, sizeof(MSG_STANDARDPARM));
  284.  
  285.     sm.Type = signal;
  286.     sm.ID = id;
  287.     sm.Parm = parm;
  288.  
  289.     pUser[conn].cSock.AddMessage((char*)&sm, sizeof(sm));
  290. }
  291.  
  292. void SendClientSignalParmCoord(int conn, int id, unsigned short signal, int parm, int x1, int y1, int x2, int y2)
  293. {
  294.     if (pMob[conn].TargetX >= x1 && pMob[conn].TargetX <= x2 && pMob[conn].TargetY >= y1 && pMob[conn].TargetY <= y2)
  295.     {
  296.  
  297.         MSG_STANDARDPARM sm;
  298.         memset(&sm, 0, sizeof(MSG_STANDARDPARM));
  299.  
  300.         sm.Type = signal;
  301.         sm.ID = id;
  302.         sm.Parm = parm;
  303.  
  304.         pUser[conn].cSock.AddMessage((char*)& sm, sizeof(sm));
  305.     }
  306. }
  307.  
  308. void SendClientSignalParm2(int conn, int id, unsigned short signal, int parm, int parm2)
  309. {
  310.     MSG_STANDARDPARM2 sm;
  311.     memset(&sm, 0, sizeof(MSG_STANDARDPARM2));
  312.  
  313.     sm.Type = signal;
  314.     sm.ID = id;
  315.     sm.Parm1 = parm;
  316.     sm.Parm2 = parm2;
  317.  
  318.     pUser[conn].cSock.AddMessage((char*)&sm, sizeof(sm));
  319. }
  320.  
  321. void SendClientSignalParm3(int conn, int id, unsigned short signal, int parm, int parm2, int parm3)
  322. {
  323.     MSG_STANDARDPARM3 sm;
  324.     memset(&sm, 0, sizeof(MSG_STANDARDPARM3));
  325.  
  326.     sm.Type = signal;
  327.     sm.ID = id;
  328.     sm.Parm1 = parm;
  329.     sm.Parm2 = parm2;
  330.     sm.Parm3 = parm3;
  331.  
  332.     pUser[conn].cSock.AddMessage((char*)&sm, sizeof(sm));
  333. }
  334.  
  335. void SendClientSignalShortParm2(int conn, int id, unsigned short signal, int parm, int parm2)
  336. {
  337.     MSG_STANDARDSHORTPARM2 sm;
  338.     memset(&sm, 0, sizeof(MSG_STANDARDSHORTPARM2));
  339.  
  340.     sm.Type = signal;
  341.     sm.ID = id;
  342.     sm.Parm1 = parm;
  343.     sm.Parm2 = parm2;
  344.  
  345.     pUser[conn].cSock.AddMessage((char*)&sm, sizeof(sm));
  346. }
  347.  
  348. void SyncMulticast(int conn, MSG_STANDARD *m, int bSend)
  349. {
  350.     for (int i = 0; i < MAX_USER; i++)
  351.     {
  352.         if (pUser[i].Mode == USER_PLAY && conn != i)
  353.         {
  354.             pUser[i].cSock.AddMessage((char*)m, m->Size);
  355.  
  356.             if (bSend)
  357.                 pUser[i].cSock.SendMessageA();
  358.         }
  359.     }
  360. }
  361.  
  362. void SyncKingdomMulticast(int conn, int Kingdom, MSG_STANDARD *m, int bSend)
  363. {
  364.     for (int i = 0; i < MAX_USER; i++)
  365.     {
  366.         if (pUser[i].Mode == USER_PLAY && conn != i && pMob[i].MOB.Clan == Kingdom && pUser[i].KingChat == 0)
  367.         {
  368.  
  369.             pUser[i].cSock.AddMessage((char*)m, m->Size);
  370.  
  371.             if (bSend)
  372.                 pUser[i].cSock.SendMessageA();
  373.         }
  374.  
  375.     }
  376. }
  377.  
  378. void SendCreateMob(int conn, int otherconn, int bSend)
  379. {
  380.     if (conn <= 0 || conn >= MAX_USER)
  381.         return;
  382.  
  383.     if (pUser[conn].Mode != USER_PLAY)
  384.         return;
  385.  
  386.     if (!pUser[conn].cSock.Sock)
  387.         return;
  388.  
  389.     MSG_CreateMob sm;
  390.     memset(&sm, 0, sizeof(MSG_CreateMob));
  391.  
  392.     if (otherconn <= 0 || otherconn >= MAX_USER || pUser[otherconn].TradeMode != 1)
  393.     {
  394.         GetCreateMob(otherconn, &sm);
  395.  
  396.         if (pUser[conn].cSock.AddMessage((char*)&sm, sizeof(MSG_CreateMob)))
  397.             pUser[conn].cSock.SendMessageA();
  398.  
  399.         return;
  400.     }
  401.  
  402.     MSG_CreateMobTrade sm2;
  403.     memset(&sm2, 0, sizeof(MSG_CreateMobTrade));
  404.  
  405.     GetCreateMobTrade(otherconn, &sm2);
  406.  
  407.     if (pUser[conn].cSock.AddMessage((char*)&sm2, sizeof(MSG_CreateMobTrade)))
  408.         pUser[conn].cSock.SendMessageA();
  409. }
  410.  
  411. void SendCreateItem(int conn, int item, int bSend)
  412. {
  413.     MSG_CreateItem sm;
  414.     memset(&sm, 0, sizeof(MSG_CreateItem));
  415.  
  416.     GetCreateItem(item, &sm);
  417.    
  418.     pUser[conn].cSock.AddMessage((char*)&sm, sizeof(MSG_CreateItem));
  419.  
  420.     if (bSend)
  421.         pUser[conn].cSock.SendMessageA();
  422. }
  423.  
  424. void SendChat(int conn, char *Message)
  425. {
  426.     MSG_MessageChat sm;
  427.     memset(&sm, 0, sizeof(MSG_MessageChat));
  428.  
  429.     sm.Type = _MSG_MessageChat;
  430.     sm.Size = sizeof(MSG_MessageChat);
  431.     sm.ID = conn;
  432.     sm.Size = sizeof(MSG_MessageChat);
  433.  
  434.     memcpy(sm.String, Message, MESSAGE_LENGTH);
  435.  
  436.     GridMulticast(pMob[conn].TargetX, pMob[conn].TargetY, (MSG_STANDARD*)&sm, conn);
  437. }
  438.  
  439. void SendEnvEffect(int x1, int y1, int x2, int y2, int Effect, int EffectParm)
  440. {
  441.     MSG_EnvEffect sm;
  442.     memset(&sm, 0, sizeof(MSG_EnvEffect));
  443.  
  444.     sm.Type = _MSG_EnvEffect;
  445.     sm.Size = sizeof(MSG_EnvEffect);
  446.     sm.ID = ESCENE_FIELD;
  447.     sm.Size = sizeof(MSG_EnvEffect);
  448.  
  449.     sm.x1 = x1;
  450.     sm.y1 = y1;
  451.     sm.x2 = x2;
  452.     sm.y2 = y2;
  453.  
  454.     sm.Effect = Effect;
  455.     sm.EffectParm = EffectParm;
  456.  
  457.     /*
  458.     for(int x = x1; x < x2; x++)
  459.     {
  460.         for(int y = y1; y < y2; y++)
  461.         {
  462.             if(x < 0 || x >= MAX_GRIDX || y < 0 || y >= MAX_GRIDY)
  463.                 continue;
  464.  
  465.             if(pMobGrid[y][x] == 0)
  466.                 continue;
  467.  
  468.             if(pMobGrid[y][x] >= MAX_USER)
  469.                 continue;
  470.  
  471.             pUser[pMobGrid[y][x]].cSock.AddMessage((char*)&sm, sizeof(MSG_EnvEffect));
  472.         }
  473.     }*/
  474.  
  475.     GridMulticast(x1 + ((x2 - x1) / 2), y1 + ((y2 - y1) / 2), (MSG_STANDARD*)&sm, 0);
  476. }
  477.  
  478. void SendEnvEffectKingdom(int x1, int y1, int x2, int y2, int Effect, int EffectParm, int Clan)
  479. {
  480.     MSG_EnvEffect sm;
  481.     memset(&sm, 0, sizeof(MSG_EnvEffect));
  482.  
  483.     sm.Type = _MSG_EnvEffect;
  484.     sm.Size = sizeof(MSG_EnvEffect);
  485.     sm.ID = ESCENE_FIELD;
  486.     sm.Size = sizeof(MSG_EnvEffect);
  487.  
  488.     sm.x1 = x1;
  489.     sm.y1 = y1;
  490.     sm.x2 = x2;
  491.     sm.y2 = y2;
  492.  
  493.     sm.Effect = Effect;
  494.     sm.EffectParm = EffectParm;
  495.  
  496.     int HaveUser = 0;
  497.    
  498.     for(int x = x1; x < x2; x++)
  499.     {
  500.         for(int y = y1; y < y2; y++)
  501.         {
  502.             if(x < 0 || x >= MAX_GRIDX || y < 0 || y >= MAX_GRIDY)
  503.                 continue;
  504.  
  505.             if(pMobGrid[y][x] == 0)
  506.                 continue;
  507.  
  508.             if(pMobGrid[y][x] >= MAX_USER)
  509.                 continue;
  510.  
  511.             int tmob = pMobGrid[y][x];
  512.  
  513.             if(pMob[tmob].MOB.Clan == Clan)
  514.                 continue;
  515.  
  516.             HaveUser++;
  517.         }
  518.     }
  519.  
  520.     if(HaveUser)
  521.         GridMulticast(x1 + ((x2 - x1) / 2), y1 + ((y2 - y1) / 2), (MSG_STANDARD*)&sm, 0);
  522. }
  523.  
  524. void SendEnvEffectLeader(int x1, int y1, int x2, int y2, int Effect, int EffectParm)
  525. {
  526.     MSG_EnvEffect sm;
  527.     memset(&sm, 0, sizeof(MSG_EnvEffect));
  528.  
  529.     sm.Type = _MSG_EnvEffect;
  530.     sm.Size = sizeof(MSG_EnvEffect);
  531.     sm.ID = ESCENE_FIELD;
  532.     sm.Size = sizeof(MSG_EnvEffect);
  533.  
  534.     sm.x1 = x1;
  535.     sm.y1 = y1;
  536.     sm.x2 = x2;
  537.     sm.y2 = y2;
  538.  
  539.     sm.Effect = Effect;
  540.     sm.EffectParm = EffectParm;
  541.  
  542.     int HaveUser = 0;
  543.     int bSend = 0;
  544.  
  545.     for(int x = x1; x < x2; x++)
  546.     {
  547.         for(int y = y1; y < y2; y++)
  548.         {
  549.             if(x < 0 || x >= MAX_GRIDX || y < 0 || y >= MAX_GRIDY)
  550.                 continue;
  551.  
  552.             if(pMobGrid[y][x] == 0)
  553.                 continue;
  554.  
  555.             if(pMobGrid[y][x] >= MAX_USER)
  556.                 continue;
  557.  
  558.             int tmob = pMobGrid[y][x];
  559.  
  560.             if(tmob == Pista[4].Party[0].LeaderID)
  561.             {
  562.                 HaveUser++;
  563.                 continue;
  564.             }
  565.  
  566.             if(tmob == Pista[4].Party[1].LeaderID)
  567.             {
  568.                 HaveUser++;
  569.                 continue;
  570.             }
  571.             if(tmob == Pista[4].Party[1].LeaderID)
  572.             {
  573.                 HaveUser++;
  574.                 continue;
  575.             }
  576.  
  577.             bSend++;
  578.         }
  579.     }
  580.  
  581.     if(HaveUser == 0 && bSend)
  582.         GridMulticast(x1 + ((x2 - x1) / 2), y1 + ((y2 - y1) / 2), (MSG_STANDARD*)&sm, 0);
  583. }
  584.  
  585. void SendRemoveMob(int dest, int sour, int Type, int bSend)
  586. {
  587.     MSG_RemoveMob sm;
  588.     memset(&sm, 0, sizeof(MSG_RemoveMob));
  589.  
  590.     sm.Type = _MSG_RemoveMob;
  591.     sm.Size = sizeof(MSG_RemoveMob);
  592.     sm.ID = sour;
  593.     sm.RemoveType = Type;
  594.  
  595.     pUser[dest].cSock.AddMessage((char*)&sm, sizeof(MSG_RemoveMob));
  596.  
  597.     if (bSend)
  598.         pUser[dest].cSock.SendMessageA();
  599. }
  600.  
  601. void SendRemoveItem(int dest, int itemid, int bSend)
  602. {
  603.     MSG_DecayItem sm_deci;
  604.     memset(&sm_deci, 0, sizeof(MSG_DecayItem));
  605.  
  606.     sm_deci.Type = _MSG_DecayItem;
  607.     sm_deci.Size = sizeof(MSG_DecayItem);
  608.     sm_deci.ID = ESCENE_FIELD;
  609.     sm_deci.ItemID = 10000 + itemid;
  610.     sm_deci.unk = 0;
  611.  
  612.     pUser[dest].cSock.AddMessage((char*)&sm_deci, sizeof(MSG_DecayItem));
  613.  
  614.     if (bSend)
  615.         pUser[dest].cSock.SendMessageA();
  616. }
  617.  
  618. void SendAutoTrade(int conn, int otherconn)
  619. {
  620.     if (conn <= 0 || conn >= MAX_USER)
  621.         return;
  622.  
  623.     if (otherconn <= 0 || otherconn >= MAX_USER)
  624.         return;
  625.  
  626.     if (pUser[otherconn].TradeMode == 0)
  627.         return;
  628.  
  629.     if (pUser[otherconn].Mode != USER_PLAY)
  630.         return;
  631.  
  632.     if (pUser[conn].Mode != USER_PLAY)
  633.         return;
  634.  
  635.     MSG_SendAutoTrade sm;
  636.     memset(&sm, 0, sizeof(MSG_SendAutoTrade));
  637.  
  638.     memcpy(&sm, &pUser[otherconn].AutoTrade, sizeof(MSG_SendAutoTrade));
  639.  
  640.     sm.ID = ESCENE_FIELD;
  641.  
  642.     sm.Index = otherconn;
  643.  
  644.     sm.Type = _MSG_SendAutoTrade;
  645.     sm.Size = sizeof(MSG_SendAutoTrade);
  646.  
  647.     if (!pUser[conn].cSock.AddMessage((char*)&sm, sizeof(MSG_UpdateCarry)))
  648.         CloseUser(conn);
  649. }
  650.  
  651. void SendGridMob(int conn)
  652. {
  653.     int posX = pMob[conn].TargetX;
  654.     int posY = pMob[conn].TargetY;
  655.  
  656.     if (conn <= 0 || conn >= MAX_USER)
  657.         return;
  658.  
  659.     int SizeY = VIEWGRIDY;
  660.     int SizeX = VIEWGRIDX;
  661.     int StartX = posX - HALFGRIDX;
  662.     int StartY = posY - HALFGRIDY;
  663.  
  664.     if ((posX - HALFGRIDX + VIEWGRIDX) >= MAX_GRIDX)
  665.         SizeX -= (StartX + SizeX - MAX_GRIDX);
  666.  
  667.     if ((posY - HALFGRIDY + VIEWGRIDY) >= MAX_GRIDY)
  668.         SizeY -= (StartY + SizeY - MAX_GRIDY);
  669.  
  670.     if (StartX < 0)
  671.         StartX = 0;
  672.  
  673.     if (StartY < 0)
  674.         StartY = 0;
  675.  
  676.  
  677.     int sx1 = StartX;
  678.     int sy1 = StartY;
  679.     int sx2 = StartX + SizeX;
  680.     int sy2 = StartY + SizeY;
  681.  
  682.     for (int y = sy1; y < sy2; y++)
  683.     {
  684.         for (int x = sx1; x < sx2; x++)
  685.         {
  686.             int tmob = pMobGrid[y][x];
  687.             int titem = pItemGrid[y][x];
  688.  
  689.             if (tmob > 0 && tmob < MAX_MOB && tmob != conn)
  690.             {
  691.                 if (pMob[tmob].Mode == MOB_EMPTY) { pMobGrid[y][x] = 0; }
  692.                 else
  693.                 {
  694.                     SendCreateMob(conn, tmob, 0);
  695.                     SendPKInfo(conn, tmob);
  696.                 }
  697.             }
  698.  
  699.             if (titem > 0 && titem < MAX_ITEM)
  700.             {
  701.                 if (pItem[titem].Mode)
  702.                     SendCreateItem(conn, titem, 0);
  703.                 else
  704.                     pItemGrid[y][x] = 0;
  705.             }
  706.         }
  707.     }
  708. }
  709.  
  710. void GridMulticast(int conn, int tx, int ty, MSG_STANDARD *msg)
  711. {
  712.     if (conn == 0 || pMob[conn].TargetX == 0)
  713.     {
  714.         Log("err,GridMulticast mobidx,pos", "-system", 0);
  715.  
  716.         return;
  717.     }
  718.  
  719.     int mobx = pMob[conn].TargetX;
  720.     int moby = pMob[conn].TargetY;
  721.  
  722.     int currentgrid = pMobGrid[moby][mobx];
  723.  
  724.     if (currentgrid != conn && currentgrid != 0)
  725.     {
  726.         if (conn >= MAX_USER)   // ÀÚ½ÅÀÇ TargetX , TargetY¿¡ ÀÚ½ÅÀÌ ¾ø´Ù. PlayerµéÀº Áß°£ ¿öÇÁ¸¦ ÇϹǷΠ°¡´É mobÀº ºÒ°¡
  727.         {
  728.             Log("NPC do not have his own grid", "-system", 0);
  729.         }
  730.         else
  731.         {
  732.             Log("PC do not have his own grid", "-system", 0);
  733.         }
  734.  
  735.         pMobGrid[moby][mobx] = 0;
  736.     }
  737.     else
  738.     {
  739.         pMobGrid[moby][mobx] = 0;
  740.     }
  741.  
  742.     if (pMobGrid[ty][tx] != conn && pMobGrid[ty][tx] != 0)
  743.     {
  744.         if (conn >= MAX_USER)
  745.         {
  746.             Log("NPC charge other mob's grid", "-system", 0);
  747.         }
  748.         else
  749.         {
  750.             Log("PC step in other mob's grid", "-system", 0);
  751.         }
  752.         pMobGrid[ty][tx] = conn;
  753.     }
  754.     else
  755.     {
  756.         pMobGrid[ty][tx] = conn;
  757.     }
  758.  
  759.  
  760.     int SizeY = VIEWGRIDY;
  761.     int SizeX = VIEWGRIDX;
  762.     int StartX = pMob[conn].TargetX - HALFGRIDX;
  763.     int StartY = pMob[conn].TargetY - HALFGRIDY;
  764.  
  765.     if (StartX + SizeX >= MAX_GRIDX)
  766.         SizeX = SizeX - (StartX + SizeX - MAX_GRIDX);
  767.  
  768.     if (SizeY + StartY >= MAX_GRIDY)
  769.         SizeY = SizeY - (StartY + SizeY - MAX_GRIDY);
  770.  
  771.     if (StartX < 0)
  772.         StartX = 0;
  773.  
  774.     if (StartY < 0)
  775.         StartY = 0;
  776.  
  777.     int sx1 = StartX;
  778.     int sy1 = StartY;
  779.     int sx2 = StartX + SizeX;
  780.     int sy2 = StartY + SizeY;
  781.  
  782.  
  783.     SizeY = VIEWGRIDY;
  784.     SizeX = VIEWGRIDX;
  785.     StartX = tx - HALFGRIDX;
  786.     StartY = ty - HALFGRIDY;
  787.  
  788.     if (StartX + SizeX >= MAX_GRIDX)
  789.         SizeX = SizeX - (StartX + SizeX - MAX_GRIDX);
  790.  
  791.     if (SizeY + StartY >= MAX_GRIDY)
  792.         SizeY = SizeY - (StartY + SizeY - MAX_GRIDY);
  793.  
  794.     if (StartX < 0)
  795.         StartX = 0;
  796.  
  797.     if (StartY < 0)
  798.         StartY = 0;
  799.  
  800.     int tx1 = StartX;
  801.     int ty1 = StartY;
  802.     int tx2 = StartX + SizeX;
  803.     int ty2 = StartY + SizeY;
  804.  
  805.     for (int y = sy1; y < sy2; y++)
  806.     {
  807.         for (int x = sx1; x < sx2; x++)
  808.         {
  809.             int tmob = pMobGrid[y][x];
  810.  
  811.             if (tmob == 0 || tmob == conn)
  812.                 continue;
  813.  
  814.             if (msg != NULL && tmob < MAX_USER)
  815.                 pUser[tmob].cSock.AddMessage((char*)msg, msg->Size);
  816.  
  817.             if (x < tx1 || x >= tx2 || y < ty1 || y >= ty2 && tx)
  818.             {
  819.                 if (tmob < MAX_USER)
  820.                     SendRemoveMob(tmob, conn, 0, 0);
  821.  
  822.                 if (conn < MAX_USER)
  823.                     SendRemoveMob(conn, tmob, 0, 0);
  824.             }
  825.         }
  826.     }
  827.  
  828.  
  829.     for (int y = sy1; y < sy2; y++)
  830.     {
  831.         for (int x = sx1; x < sx2; x++)
  832.         {
  833.             int titem = pItemGrid[y][x];
  834.  
  835.             if (titem == 0)
  836.                 continue;
  837.  
  838.             if (x < tx1 || x >= tx2 || y < ty1 || y >= ty2 && tx)
  839.             {
  840.                 if (titem > 0 && titem < MAX_ITEM && pItem[titem].Mode && pItem[titem].ITEM.sIndex && conn > 0 && conn < MAX_USER)
  841.                     SendRemoveItem(conn, titem, 0);
  842.             }
  843.         }
  844.     }
  845.  
  846.     for (int y = ty1; y < ty2; y++)
  847.     {
  848.         for (int x = tx1; x < tx2; x++)
  849.         {
  850.             int titem = pItemGrid[y][x];
  851.             int tmob = pMobGrid[y][x];
  852.  
  853.             if (x < sx1 || x >= sx2 || y < sy1 || y >= sy2)
  854.             {
  855.                 if (titem > 0 && titem < MAX_ITEM && pItem[titem].Mode && pItem[titem].ITEM.sIndex && conn < MAX_USER)
  856.                 {
  857.                     if (pItem[titem].Mode)
  858.                         SendCreateItem(conn, titem, 0);
  859.  
  860.                     else
  861.                         pItemGrid[y][x] = 0;
  862.                 }
  863.  
  864.                 if (tmob != conn && tmob)
  865.                 {
  866.                     if (tmob < MAX_USER)
  867.                     {
  868.                             SendCreateMob(tmob, conn, 0);
  869.                             SendPKInfo(tmob, conn);
  870.                     }
  871.  
  872.                     if (conn < MAX_USER)
  873.                     {
  874.                             SendCreateMob(conn, tmob, 0);
  875.                             SendPKInfo(conn, tmob);
  876.                     }
  877.  
  878.                     if (msg != NULL && tmob > 0 && tmob < MAX_USER)
  879.                     {
  880.                         if (pUser[tmob].cSock.AddMessage((char*)msg, msg->Size) == 0)
  881.                         {
  882.                             pUser[tmob].AccountName[ACCOUNTNAME_LENGTH - 1] = 0;
  883.                             pUser[tmob].AccountName[ACCOUNTNAME_LENGTH - 2] = 0;
  884.  
  885.                             sprintf(temp, "err,gridmulticast add %d-%d %s", tmob, pUser[tmob].Mode, pUser[tmob].AccountName);
  886.                             Log(temp, "-system", 0);
  887.                         }
  888.                     }
  889.                 }
  890.             }
  891.         }
  892.     }
  893.  
  894.     MSG_Action *sm = (MSG_Action*)msg;
  895.  
  896.     pMob[conn].LastTime = sm->ClientTick;
  897.     pMob[conn].LastSpeed = sm->Speed;
  898.  
  899.     pMob[conn].LastX = sm->PosX;
  900.     pMob[conn].LastY = sm->PosY;
  901.  
  902.     pMob[conn].TargetX = tx;
  903.     pMob[conn].TargetY = ty;
  904. }
  905.  
  906. void SendEmotion(int conn, int Motion, int Parm)
  907. {
  908.     MSG_Motion sm;
  909.     memset(&sm, 0, sizeof(MSG_Motion));
  910.  
  911.     sm.Type = _MSG_Motion;
  912.     sm.Size = sizeof(MSG_Motion);
  913.  
  914.     sm.NotUsed = 0;
  915.  
  916.     sm.ID = conn;
  917.  
  918.     sm.Motion = Motion;
  919.     sm.Parm = Parm;
  920.  
  921.     GridMulticast(pMob[conn].TargetX, pMob[conn].TargetY, (MSG_STANDARD*)&sm, 0);
  922. }
  923.  
  924. void GridMulticast(int tx, int ty, MSG_STANDARD *msg, int skip)
  925. {
  926.     int SizeY = VIEWGRIDY;
  927.     int SizeX = VIEWGRIDX;
  928.     int StartX = tx - HALFGRIDX;
  929.     int StartY = ty - HALFGRIDY;
  930.  
  931.     if (StartX + SizeX >= MAX_GRIDX)
  932.         SizeX = SizeX - (StartX + SizeX - MAX_GRIDX);
  933.  
  934.     if (SizeY + StartY >= MAX_GRIDY)
  935.         SizeY = SizeY - (StartY + SizeY - MAX_GRIDY);
  936.  
  937.     if (StartX < 0)
  938.     {
  939.         StartX = 0;
  940.  
  941.         SizeX = SizeX + StartX;
  942.     }
  943.  
  944.     if (StartY < 0)
  945.     {
  946.         StartY = 0;
  947.  
  948.         SizeY = SizeY + StartY;
  949.     }
  950.  
  951.     int sx1 = StartX;
  952.     int sy1 = StartY;
  953.     int sx2 = StartX + SizeX;
  954.     int sy2 = StartY + SizeY;
  955.  
  956.     for (int y = sy1; y < sy2; y++)
  957.     {
  958.         for (int x = sx1; x < sx2; x++)
  959.         {
  960.             int tmob = pMobGrid[y][x];
  961.  
  962.             if (tmob <= 0 || tmob == skip)
  963.                 continue;
  964.  
  965.             if (msg != NULL && tmob < MAX_USER)
  966.             {
  967.                 if (msg->Type == _MSG_CreateMob)
  968.                 {
  969.                     int xx = ((MSG_CreateMob*)msg)->PosX;
  970.                     int yy = ((MSG_CreateMob*)msg)->PosY;
  971.  
  972.                     if(xx >= 896 && yy >= 1405 && xx <= 1150 && yy <= 1538)
  973.                     {
  974.                         STRUCT_ITEM hcitem;
  975.  
  976.                         memset(&hcitem, 0, sizeof(STRUCT_ITEM));
  977.  
  978.                         hcitem.sIndex = 3505;
  979.  
  980.                         ((MSG_CreateMob*)msg)->Equip[1] = BASE_VisualItemCode(&hcitem, 1);
  981.  
  982.                         ((MSG_CreateMob*)msg)->AnctCode[1] = BASE_VisualAnctCode(&hcitem);
  983.  
  984.  
  985.                         hcitem.sIndex = 3999;
  986.  
  987.                         ((MSG_CreateMob*)msg)->Equip[15] = BASE_VisualItemCode(&hcitem, 15);
  988.  
  989.                         ((MSG_CreateMob*)msg)->AnctCode[15] = BASE_VisualAnctCode(&hcitem);
  990.                     }
  991.  
  992.                 }
  993.  
  994.                 if (msg->Type == _MSG_CNFMobKill)
  995.                 {
  996.                     ((MSG_CNFMobKill*)msg)->Exp = pMob[tmob].MOB.Exp;
  997.                     ((MSG_CNFMobKill*)msg)->Hold = pMob[tmob].Extra.Hold;
  998.  
  999.                     int Segment = pMob[tmob].CheckGetLevel();
  1000.  
  1001.                     if (Segment >= 1 && Segment <= 4)
  1002.                     {
  1003.                         if (Segment == 4)
  1004.                         {
  1005.                             SetCircletSubGod(tmob);
  1006.                             SendClientMsg(tmob, g_pMessageStringTable[_NN_Level_Up]);
  1007.  
  1008.                             if (pMob[tmob].Extra.ClassMaster == MORTAL)
  1009.                                 DoItemLevel(tmob);
  1010.                         }
  1011.  
  1012.                         if (Segment == 3)
  1013.                             SendClientMsg(tmob, g_pMessageStringTable[_NN_3_Quarters_Bonus]);
  1014.  
  1015.                         if (Segment == 2)
  1016.                             SendClientMsg(tmob, g_pMessageStringTable[_NN_2_Quarters_Bonus]);
  1017.  
  1018.                         if (Segment == 1)
  1019.                             SendClientMsg(tmob, g_pMessageStringTable[_NN_1_Quarters_Bonus]);
  1020.  
  1021.                         SendScore(tmob);
  1022.                         SendEmotion(tmob, 14, 3);
  1023.  
  1024.                         if (Segment == 4)
  1025.                         {
  1026.                             SendEtc(tmob);
  1027.  
  1028.                             int PKPoint = GetPKPoint(tmob) + 5;
  1029.                             SetPKPoint(tmob, PKPoint);
  1030.  
  1031.                             MSG_CreateMob sm_lupc;
  1032.                             memset(&sm_lupc, 0, sizeof(MSG_CreateMob));
  1033.                             GetCreateMob(tmob, &sm_lupc);
  1034.  
  1035.                             GridMulticast(pMob[tmob].TargetX, pMob[tmob].TargetY, (MSG_STANDARD*)&sm_lupc, 0);
  1036.  
  1037.                             sprintf(temp, "lvl %s level up to %d", pMob[tmob].MOB.MobName, pMob[tmob].MOB.BaseScore.Level);
  1038.                             Log(temp, pUser[tmob].AccountName, pUser[tmob].IP);
  1039.                         }
  1040.                     }
  1041.                 }
  1042.  
  1043.                 pUser[tmob].cSock.AddMessage((char*)msg, msg->Size);
  1044.             }
  1045.         }
  1046.     }
  1047. }
  1048.  
  1049. void PartyGridMulticast(int tx, int ty, MSG_STANDARD *msg, int skip, int Leaderconn)
  1050. {
  1051.     int SizeY = VIEWGRIDY;
  1052.     int SizeX = VIEWGRIDX;
  1053.     int StartX = tx - HALFGRIDX;
  1054.     int StartY = ty - HALFGRIDY;
  1055.  
  1056.     if (StartX + SizeX >= MAX_GRIDX)
  1057.         SizeX = SizeX - (StartX + SizeX - MAX_GRIDX);
  1058.  
  1059.     if (SizeY + StartY >= MAX_GRIDY)
  1060.         SizeY = SizeY - (StartY + SizeY - MAX_GRIDY);
  1061.  
  1062.     if (StartX < 0)
  1063.         StartX = 0;
  1064.  
  1065.     if (StartY < 0)
  1066.         StartY = 0;
  1067.  
  1068.     int sx1 = StartX;
  1069.     int sy1 = StartY;
  1070.     int sx2 = StartX + SizeX;
  1071.     int sy2 = StartY + SizeY;
  1072.  
  1073.     for (int y = StartY; y < sy2; y++)
  1074.     {
  1075.         for (int x = sx1; x < sx2; x++)
  1076.         {
  1077.             int tmob = pMobGrid[y][x];
  1078.  
  1079.             if (tmob <= 0 || tmob == Leaderconn)
  1080.                 continue;
  1081.  
  1082.             if (!Leaderconn || pMob[tmob].Leader != Leaderconn)
  1083.             {
  1084.                 if (pMob[tmob].Mode == MOB_EMPTY)
  1085.                 {
  1086.                     int Unk = 0;
  1087.  
  1088.                     continue;
  1089.                 }
  1090.  
  1091.                 if (msg != NULL && tmob < MAX_USER && tmob != skip && !pUser[tmob].PartyChat)
  1092.                 {
  1093.                     if (pUser[tmob].Mode != USER_PLAY || pUser[tmob].cSock.Sock == 0)
  1094.                         continue;
  1095.  
  1096.                     pUser[tmob].cSock.AddMessage((char*)msg, msg->Size);
  1097.                 }
  1098.             }
  1099.         }
  1100.     }
  1101.  
  1102.     if (Leaderconn > 0 && Leaderconn < MAX_USER && pUser[Leaderconn].Mode == USER_PLAY)
  1103.     {
  1104.         if (Leaderconn != skip)
  1105.             pUser[Leaderconn].cSock.AddMessage((char*)msg, msg->Size);
  1106.  
  1107.         for (int i = 0; i < MAX_PARTY; i++)
  1108.         {
  1109.             int partyconn = pMob[Leaderconn].PartyList[i];
  1110.  
  1111.             if (partyconn <= 0 || partyconn >= MAX_USER)
  1112.                 continue;
  1113.  
  1114.             if (partyconn == skip)
  1115.                 continue;
  1116.  
  1117.             if (pUser[partyconn].Mode != USER_PLAY || pUser[partyconn].PartyChat != 0)
  1118.                 continue;
  1119.  
  1120.             if (pUser[partyconn].Mode != USER_PLAY || pUser[partyconn].cSock.Sock == 0)
  1121.                 continue;
  1122.  
  1123.             if (!pUser[partyconn].cSock.AddMessage((char*)msg, msg->Size))
  1124.                 CloseUser(partyconn);
  1125.         }
  1126.     }
  1127. }
  1128.  
  1129. void SendItem(int conn, int Type, int Slot, STRUCT_ITEM *item)
  1130. {
  1131.     if (conn <= 0 || conn >= MAX_USER)
  1132.         return;
  1133.  
  1134.     if (pUser[conn].Mode != USER_PLAY)
  1135.         return;
  1136.  
  1137.     if (pUser[conn].cSock.Sock == 0)
  1138.         return;
  1139.  
  1140.     MSG_SendItem sm_si;
  1141.     memset(&sm_si, 0, sizeof(MSG_SendItem));
  1142.  
  1143.     sm_si.Type = _MSG_SendItem;
  1144.     sm_si.Size = sizeof(MSG_SendItem);
  1145.     sm_si.ID = conn;
  1146.  
  1147.     sm_si.invType = Type;
  1148.     sm_si.Slot = Slot;
  1149.  
  1150.     //*(int*)&sm_si.item = *(int*)&item;
  1151.     //*(int*)((int)&sm_si.item + 4) = *(int*)((int)&item + 4);
  1152.  
  1153.     memcpy(&sm_si.item, item, sizeof(STRUCT_ITEM));
  1154.  
  1155.     pUser[conn].cSock.AddMessage((char*)&sm_si, sizeof(MSG_SendItem));
  1156. }
  1157.  
  1158. void SendEquip(int conn, int skip)
  1159. {
  1160.     MSG_UpdateEquip sm_ue;
  1161.     memset(&sm_ue, 0, sizeof(MSG_UpdateEquip));
  1162.  
  1163.     sm_ue.Type = _MSG_UpdateEquip;
  1164.     sm_ue.Size = sizeof(MSG_UpdateEquip);
  1165.     sm_ue.ID = conn;
  1166.  
  1167.     int SendMount = 0;
  1168.  
  1169.     for (int i = 0; i < MAX_EQUIP; i++)
  1170.     {
  1171.         STRUCT_ITEM *item = &pMob[conn].MOB.Equip[i];
  1172.  
  1173.         sm_ue.Equip[i] = BASE_VisualItemCode(item, i);
  1174.  
  1175.         sm_ue.AnctCode[i] = BASE_VisualAnctCode(item);
  1176.  
  1177.         if (i == 14 && sm_ue.Equip[14] >= 2360 && sm_ue.Equip[i] < 2390 && pMob[conn].MOB.Equip[i].stEffect[0].sValue <= 0)
  1178.         {
  1179.             sm_ue.Equip[i] = 0;
  1180.  
  1181.             SendMount = 1;
  1182.  
  1183.             continue;
  1184.         }
  1185.  
  1186.         if (i == 14 && sm_ue.Equip[14] >= 2360 && sm_ue.Equip[i] < 2390)
  1187.         {
  1188.             int MountLevel = pMob[conn].MOB.Equip[i].stEffect[1].cEffect; // level
  1189.  
  1190.             MountLevel /= 10;
  1191.  
  1192.             if (MountLevel > 13)
  1193.                 MountLevel = 13;
  1194.             if (MountLevel < 0)
  1195.                 MountLevel = 0;
  1196.  
  1197.             MountLevel = MountLevel * 4096;
  1198.             sm_ue.Equip[i] += MountLevel;
  1199.  
  1200.             continue;
  1201.         }
  1202.     }
  1203.  
  1204.     GridMulticast(pMob[conn].TargetX, pMob[conn].TargetY, (MSG_STANDARD*)&sm_ue, skip);
  1205.  
  1206.     if (SendMount != 0)
  1207.         SendItem(conn, ITEM_PLACE_EQUIP, 14, &pMob[conn].MOB.Equip[14]);
  1208. }
  1209.  
  1210. void SendScore(int conn)
  1211. {
  1212.     MSG_UpdateScore sm_vus;
  1213.     memset(&sm_vus, 0, sizeof(MSG_UpdateScore));
  1214.  
  1215.     sm_vus.Type = _MSG_UpdateScore;
  1216.  
  1217.     if (conn < MAX_USER)
  1218.     {
  1219.         sm_vus.CurrHp = pMob[conn].MOB.CurrentScore.Hp;
  1220.         sm_vus.CurrMp = pMob[conn].MOB.CurrentScore.Mp;
  1221.     }
  1222.  
  1223.     sm_vus.Size = sizeof(MSG_UpdateScore);
  1224.     sm_vus.ID = conn;
  1225.  
  1226.     memcpy(&sm_vus.Score, &pMob[conn].MOB.CurrentScore, sizeof(STRUCT_SCORE));
  1227.  
  1228.     sm_vus.Critical = pMob[conn].MOB.Critical;
  1229.     sm_vus.SaveMana = pMob[conn].MOB.SaveMana;
  1230.     sm_vus.Guild = pMob[conn].MOB.Guild;
  1231.     sm_vus.GuildLevel = pMob[conn].MOB.GuildLevel;
  1232.  
  1233.     GetAffect(sm_vus.Affect, pMob[conn].Affect);
  1234.  
  1235.     sm_vus.Resist[0] = pMob[conn].MOB.Resist[0];
  1236.     sm_vus.Resist[1] = pMob[conn].MOB.Resist[1];
  1237.     sm_vus.Resist[2] = pMob[conn].MOB.Resist[2];
  1238.     sm_vus.Resist[3] = pMob[conn].MOB.Resist[3];
  1239.  
  1240.     sm_vus.Special[0] = 0xCC;
  1241.     sm_vus.Special[1] = 0xCC;
  1242.     sm_vus.Special[2] = 0xCC;
  1243.     sm_vus.Special[3] = 0xCC;
  1244.  
  1245.     sm_vus.Magic = pMob[conn].MOB.Magic;
  1246.  
  1247.     if (pMob[conn].GuildDisable)
  1248.         sm_vus.Guild = 0;
  1249.  
  1250.     if (BrState != 0)
  1251.     {
  1252.         if (conn < MAX_USER)
  1253.         {
  1254.             int posX = pMob[conn].TargetX;
  1255.             int posY = pMob[conn].TargetY;
  1256.  
  1257.             if (posX >= 2604 && posY >= 1708 && posX <= 2648 && posY <= 1744)
  1258.             {
  1259.                 sm_vus.Guild = 0;
  1260.                 sm_vus.GuildLevel = 0;
  1261.             }
  1262.         }
  1263.     }
  1264.     GridMulticast(pMob[conn].TargetX, pMob[conn].TargetY, (MSG_STANDARD*)&sm_vus, 0);
  1265.  
  1266.     SendAffect(conn);
  1267. }
  1268.  
  1269. void SendEtc(int conn)
  1270. {
  1271.     if (conn <= 0 || conn >= MAX_USER)
  1272.         return;
  1273.  
  1274.     if (pUser[conn].Mode != USER_PLAY)
  1275.         return;
  1276.  
  1277.     if (pUser[conn].cSock.Sock == 0)
  1278.         return;
  1279.  
  1280.     MSG_UpdateEtc sm;
  1281.  
  1282.     memset(&sm, 0, sizeof(MSG_UpdateEtc));
  1283.  
  1284.     sm.Type = _MSG_UpdateEtc;
  1285.     sm.Size = sizeof(MSG_UpdateEtc);
  1286.  
  1287.     sm.ID = conn;
  1288.  
  1289.     sm.Exp = pMob[conn].MOB.Exp;
  1290.  
  1291.     sm.SpecialBonus = pMob[conn].MOB.SpecialBonus;
  1292.  
  1293.     sm.Learn = pMob[conn].MOB.LearnedSkill;
  1294.     sm.SecLearn = pMob[conn].Extra.SecLearnedSkill;
  1295.  
  1296.     sm.ScoreBonus = pMob[conn].MOB.ScoreBonus;
  1297.     sm.SkillBonus = pMob[conn].MOB.SkillBonus;
  1298.  
  1299.     sm.Coin = pMob[conn].MOB.Coin;
  1300.  
  1301.     sm.Hold = pMob[conn].Extra.Hold;
  1302.     sm.Magic = pMob[conn].MOB.Magic;
  1303.  
  1304.     if (!pUser[conn].cSock.AddMessage((char*)&sm, sizeof(MSG_UpdateEtc)))
  1305.         CloseUser(conn);
  1306. }
  1307.  
  1308. void SendCargoCoin(int conn)
  1309. {
  1310.     if (conn <= 0 || conn >= MAX_USER)
  1311.         return;
  1312.  
  1313.     if (pUser[conn].Mode != USER_PLAY)
  1314.         return;
  1315.  
  1316.     if (pUser[conn].cSock.Sock == 0)
  1317.         return;
  1318.  
  1319.     MSG_STANDARDPARM sm_ucc;
  1320.     memset(&sm_ucc, 0, sizeof(MSG_STANDARDPARM));
  1321.  
  1322.     sm_ucc.Type = _MSG_UpdateCargoCoin;
  1323.     sm_ucc.Size = sizeof(MSG_STANDARDPARM);
  1324.     sm_ucc.Size = sizeof(MSG_STANDARDPARM);
  1325.  
  1326.     sm_ucc.ID = ESCENE_FIELD;
  1327.  
  1328.     sm_ucc.Parm = pUser[conn].Coin;
  1329.  
  1330.     if (!pUser[conn].cSock.AddMessage((char*)&sm_ucc, sizeof(MSG_STANDARDPARM)))
  1331.         CloseUser(conn);
  1332. }
  1333.  
  1334. void SendGuildList(int conn)
  1335. {
  1336.     int Guild = pMob[conn].MOB.Guild;
  1337.  
  1338.     if (Guild <= 0)
  1339.         return;
  1340.  
  1341.     char str[128];
  1342.  
  1343.     memset(str, 0, 128);
  1344.  
  1345.     int members = 0;
  1346.     int max_size = 70;
  1347.  
  1348.     for (int i = 0; i < MAX_USER; i++)
  1349.     {
  1350.         if (pUser[i].Mode != USER_PLAY)
  1351.             continue;
  1352.  
  1353.         if (Guild != pMob[i].MOB.Guild)
  1354.             continue;
  1355.  
  1356.         members++;
  1357.  
  1358.         int len = strlen(str);
  1359.  
  1360.         if (len >= max_size)
  1361.         {
  1362.             SendClientMsg(conn, str);
  1363.  
  1364.             memset(str, 0, len);
  1365.         }
  1366.  
  1367.         pMob[i].MOB.MobName[NAME_LENGTH - 1] = 0;
  1368.         pMob[i].MOB.MobName[NAME_LENGTH - 2] = 0;
  1369.  
  1370.         strcat(str, pMob[i].MOB.MobName);
  1371.         strcat(str, " ");
  1372.     }
  1373.  
  1374.     if (str[0])
  1375.         SendClientMsg(conn, str);
  1376.  
  1377.     if (members == 0)
  1378.         SendClientMsg(conn, g_pMessageStringTable[_NN_No_Guild_Members]);
  1379.  
  1380.     int max_guild = 65536;
  1381.  
  1382.     if (pMob[conn].MOB.Guild <= 0 || pMob[conn].MOB.Guild >= max_guild)
  1383.         return;
  1384.  
  1385.     int gwar = g_pGuildWar[Guild];
  1386.     char GuildName[256];
  1387.  
  1388.     BASE_GetGuildName(ServerGroup, gwar, GuildName);
  1389.  
  1390.     int FoundWar = -1;
  1391.  
  1392.     if (gwar > 0 && gwar < max_guild)
  1393.     {
  1394.         if (Guild == g_pGuildWar[gwar])
  1395.         {
  1396.             sprintf(str, g_pMessageStringTable[_SN_Your_are_at_war], GuildName);
  1397.             SendClientMsg(conn, str);
  1398.  
  1399.             FoundWar = g_pGuildWar[gwar];
  1400.         }
  1401.         else
  1402.         {
  1403.             sprintf(str, g_pMessageStringTable[_SN_War_to_S], GuildName);
  1404.             SendClientMsg(conn, str);
  1405.         }
  1406.     }
  1407.  
  1408.     for (int j = 1; j < max_guild; j++)
  1409.     {
  1410.         if (g_pGuildWar[j] == Guild || g_pGuildWar[j] == 0)
  1411.             continue;
  1412.  
  1413.         if (j == FoundWar)
  1414.             continue;
  1415.  
  1416.         BASE_GetGuildName(ServerGroup, j, GuildName);
  1417.  
  1418.         sprintf(str, g_pMessageStringTable[_SN_War_from_S], GuildName);
  1419.         SendClientMsg(conn, str);
  1420.     }
  1421.  
  1422.     int ally = g_pGuildAlly[Guild];
  1423.  
  1424.     BASE_GetGuildName(ServerGroup, ally, GuildName);
  1425.  
  1426.     if (ally > 0 && ally < max_guild)
  1427.     {
  1428.         sprintf(str, g_pMessageStringTable[_SN_Ally_to_S], GuildName);
  1429.         SendClientMsg(conn, str);
  1430.     }
  1431.  
  1432.     for (int j = 1; j < max_guild; j++)
  1433.     {
  1434.         if (g_pGuildAlly[j] == Guild || g_pGuildAlly[j] == 0)
  1435.             continue;
  1436.  
  1437.         BASE_GetGuildName(ServerGroup, j, GuildName);
  1438.  
  1439.         sprintf(str, g_pMessageStringTable[_SN_Ally_from_S], GuildName);
  1440.         SendClientMsg(conn, str);
  1441.     }
  1442. }
  1443.  
  1444. void SendShopList(int conn, int MobIndex, int ShopType)
  1445. {
  1446.     if (conn <= 0 || conn >= MAX_USER)
  1447.         return;
  1448.  
  1449.     if (pUser[conn].Mode != USER_PLAY)
  1450.         return;
  1451.  
  1452.     if (pUser[conn].cSock.Sock == 0)
  1453.         return;
  1454.  
  1455.     MSG_ShopList sm_sl;
  1456.     memset(&sm_sl, 0, sizeof(MSG_ShopList));
  1457.  
  1458.     sm_sl.Type = _MSG_ShopList;
  1459.     sm_sl.Size = sizeof(MSG_ShopList);
  1460.  
  1461.     sm_sl.ID = ESCENE_FIELD;
  1462.  
  1463.     sm_sl.ShopType = ShopType;
  1464.  
  1465.     for (int i = 0; i < MAX_SHOPLIST; i++)
  1466.     {
  1467.         int tx = i / 9;
  1468.         int ty = i % 9 + MAX_SHOPLIST * i / 9;
  1469.  
  1470.         int invpos = (i % 9) + ((i / 9) * MAX_SHOPLIST);
  1471.  
  1472.  
  1473.         *(int*)&sm_sl.List[i] = *(int*)&pMob[MobIndex].MOB.Carry[invpos].sIndex;
  1474.         *(int*)((int)&sm_sl.List[i] + 4) = *(int*)((int)&pMob[MobIndex].MOB.Carry[invpos] + 4);
  1475.     }
  1476.  
  1477.     int posX = pMob[MobIndex].TargetX;
  1478.     int posY = pMob[MobIndex].TargetY;
  1479.  
  1480.     int village = BASE_GetVillage(posX, posY);
  1481.  
  1482.     if (village >= 0 && village < MAX_GUILDZONE)
  1483.         sm_sl.Tax = g_pGuildZone[village].CityTax;
  1484.     else
  1485.         sm_sl.Tax = 0;
  1486.  
  1487.     if (!pUser[conn].cSock.AddMessage((char*)&sm_sl, sizeof(MSG_ShopList)))
  1488.         CloseUser(conn);
  1489. }
  1490.  
  1491. void SendWarInfo(int conn, int Clan)
  1492. {
  1493.     int Guild = 0;
  1494.     int max_guild = 65536;
  1495.  
  1496.     if (pMob[conn].MOB.Guild <= 0 || pMob[conn].MOB.Guild >= max_guild)
  1497.         pMob[conn].MOB.Guild = 0;
  1498.  
  1499.     if (g_pGuildWar[pMob[conn].MOB.Guild] <= 0 || g_pGuildWar[pMob[conn].MOB.Guild] >= max_guild)
  1500.         g_pGuildWar[pMob[conn].MOB.Guild] = 0;
  1501.  
  1502.     if (g_pGuildAlly[pMob[conn].MOB.Guild] <= 0 || g_pGuildAlly[pMob[conn].MOB.Guild] >= max_guild)
  1503.         g_pGuildAlly[pMob[conn].MOB.Guild] = 0;
  1504.  
  1505.     if (pMob[conn].MOB.Guild && g_pGuildWar[pMob[conn].MOB.Guild] && g_pGuildWar[g_pGuildWar[pMob[conn].MOB.Guild]] == pMob[conn].MOB.Guild)
  1506.         Guild = g_pGuildWar[pMob[conn].MOB.Guild];
  1507.     else
  1508.         Guild = 0;
  1509.  
  1510.     SendClientSignalParm3(conn, 30000, _MSG_SendWarInfo, Guild, Clan, g_pGuildAlly[pMob[conn].MOB.Guild]);
  1511. }
  1512.  
  1513. void SendReqParty(int conn, int Leaderconn, int PartyID)
  1514. {
  1515.     if (conn <= 0 || conn >= MAX_USER)
  1516.         return;
  1517.  
  1518.     if (pUser[conn].Mode != USER_PLAY)
  1519.         return;
  1520.  
  1521.     if (pUser[conn].cSock.Sock == 0)
  1522.         return;
  1523.  
  1524.     MSG_SendReqParty sm_srp;
  1525.     memset(&sm_srp, 0, sizeof(MSG_SendReqParty));
  1526.  
  1527.     sm_srp.ID = ESCENE_FIELD;
  1528.     sm_srp.Type = _MSG_SendReqParty;
  1529.     sm_srp.Size = sizeof(MSG_SendReqParty);
  1530.  
  1531.     sm_srp.Class = pMob[Leaderconn].MOB.Class;
  1532.  
  1533.     sm_srp.Level = pMob[Leaderconn].MOB.CurrentScore.Level;
  1534.     sm_srp.MaxHp = pMob[Leaderconn].MOB.CurrentScore.MaxHp;
  1535.     sm_srp.Hp = pMob[Leaderconn].MOB.CurrentScore.Hp;
  1536.  
  1537.     sm_srp.PartyPos = 0;
  1538.  
  1539.     sm_srp.PartyID = PartyID;
  1540.  
  1541.     strcpy(sm_srp.MobName, pMob[Leaderconn].MOB.MobName);
  1542.  
  1543.     if (!pUser[conn].cSock.AddMessage((char*)&sm_srp, sizeof(MSG_SendReqParty)))
  1544.         CloseUser(conn);
  1545. }
  1546.  
  1547. void SendAddParty(int Leaderconn, int conn, int PartyID)
  1548. {
  1549.     if (Leaderconn <= 0 || Leaderconn >= MAX_USER)
  1550.         return;
  1551.  
  1552.     if (pUser[Leaderconn].Mode != USER_PLAY)
  1553.         return;
  1554.  
  1555.     if (pUser[Leaderconn].cSock.Sock == 0)
  1556.         return;
  1557.  
  1558.     MSG_CNFAddParty sm_cap;
  1559.     memset(&sm_cap, 0, sizeof(MSG_CNFAddParty));
  1560.  
  1561.     sm_cap.ID = ESCENE_FIELD;
  1562.     sm_cap.Type = _MSG_CNFAddParty;
  1563.     sm_cap.Size = sizeof(MSG_CNFAddParty);
  1564.  
  1565.     if (PartyID == 0)
  1566.         sm_cap.Leaderconn = conn;
  1567.     else
  1568.         sm_cap.Leaderconn = 30000;
  1569.  
  1570.     sm_cap.Level = pMob[conn].MOB.CurrentScore.Level;
  1571.     sm_cap.MaxHp = pMob[conn].MOB.CurrentScore.MaxHp > 32000 ? ((pMob[conn].MOB.CurrentScore.MaxHp+1) / 100) : pMob[conn].MOB.CurrentScore.MaxHp;
  1572.     sm_cap.Hp = pMob[conn].MOB.CurrentScore.Hp > 32000 ? ((pMob[conn].MOB.CurrentScore.Hp+1) / 100) : pMob[conn].MOB.CurrentScore.Hp;
  1573.  
  1574.     sm_cap.PartyID = conn;//Check:
  1575.     sm_cap.Target = (short)52428;
  1576.  
  1577.     strcpy(sm_cap.MobName, pMob[conn].MOB.MobName);
  1578.  
  1579.     if (!pUser[Leaderconn].cSock.SendOneMessage((char*)&sm_cap, sizeof(MSG_CNFAddParty)))
  1580.         CloseUser(Leaderconn);
  1581. }
  1582.  
  1583. void SendRemoveParty(int conn, int connExit)
  1584. {
  1585.     if (conn <= 0 || conn >= MAX_USER)
  1586.         return;
  1587.  
  1588.     if (pUser[conn].Mode != USER_PLAY)
  1589.         return;
  1590.  
  1591.     if (pUser[conn].cSock.Sock == 0)
  1592.         return;
  1593.  
  1594.  
  1595.     MSG_RemoveParty sm_rp;
  1596.     memset(&sm_rp, 0, sizeof(MSG_RemoveParty));
  1597.  
  1598.     sm_rp.ID = ESCENE_FIELD;
  1599.     sm_rp.Type = _MSG_RemoveParty;
  1600.     sm_rp.Size = sizeof(MSG_RemoveParty);
  1601.  
  1602.     sm_rp.Leaderconn = connExit;
  1603.     sm_rp.unk = 0;
  1604.  
  1605.     if (!pUser[conn].cSock.AddMessage((char*)&sm_rp, sizeof(MSG_RemoveParty)))
  1606.         CloseUser(conn);
  1607. }
  1608.  
  1609. void SendCarry(int conn)
  1610. {
  1611.     if (conn <= 0 || conn >= MAX_USER)
  1612.         return;
  1613.  
  1614.     if (pUser[conn].Mode != USER_PLAY)
  1615.         return;
  1616.  
  1617.     if (pUser[conn].cSock.Sock == 0)
  1618.         return;
  1619.  
  1620.     MSG_UpdateCarry sm;
  1621.  
  1622.     memset(&sm, 0, sizeof(MSG_UpdateCarry));
  1623.  
  1624.     sm.ID = conn;
  1625.     sm.Type = _MSG_UpdateCarry;
  1626.     sm.Size = sizeof(MSG_UpdateCarry);
  1627.  
  1628.     memcpy(&sm.Carry, pMob[conn].MOB.Carry, sizeof(STRUCT_ITEM)*MAX_CARRY);
  1629.  
  1630.     sm.Coin = pMob[conn].MOB.Coin;
  1631.  
  1632.     if (!pUser[conn].cSock.AddMessage((char*)&sm, sizeof(MSG_UpdateCarry)))
  1633.         CloseUser(conn);
  1634. }
  1635.  
  1636. void SendWeather()
  1637. {
  1638.     MSG_UpdateWeather sm_uw;
  1639.     memset(&sm_uw, 0, sizeof(MSG_UpdateWeather));
  1640.  
  1641.     sm_uw.Type = _MSG_UpdateWeather;
  1642.     sm_uw.Size = sizeof(MSG_UpdateWeather);
  1643.  
  1644.     sm_uw.ID = ESCENE_FIELD;
  1645.  
  1646.     sm_uw.CurrentWeather = CurrentWeather;
  1647.  
  1648.     for (int i = 0; i < MAX_USER; i++)
  1649.     {
  1650.         if (pUser[i].Mode != USER_PLAY)
  1651.             continue;
  1652.  
  1653.         if (!pUser[i].cSock.Sock)
  1654.             continue;
  1655.  
  1656.         if (!pUser[i].cSock.AddMessage((char*)&sm_uw, sizeof(MSG_UpdateWeather))) CloseUser(i);
  1657.     }
  1658. }
  1659.  
  1660. void SendHpMp(int conn)
  1661. {
  1662.     if (conn <= 0 || conn >= MAX_USER)
  1663.         return;
  1664.  
  1665.     if (pUser[conn].Mode != USER_PLAY)
  1666.         return;
  1667.  
  1668.     if (pUser[conn].cSock.Sock == 0)
  1669.         return;
  1670.  
  1671.     MSG_SetHpMp sm_shm;
  1672.     memset(&sm_shm, 0, sizeof(MSG_SetHpMp));
  1673.  
  1674.     sm_shm.Type = _MSG_SetHpMp;
  1675.     sm_shm.Size = sizeof(MSG_SetHpMp);
  1676.     sm_shm.ID = conn;
  1677.  
  1678.     sm_shm.Hp = pMob[conn].MOB.CurrentScore.Hp;
  1679.     sm_shm.Mp = pMob[conn].MOB.CurrentScore.Mp;
  1680.  
  1681.     GridMulticast(pMob[conn].TargetX, pMob[conn].TargetY, (MSG_STANDARD*)&sm_shm, 0);
  1682. }
  1683.  
  1684. void SendSetHpMp(int conn)
  1685. {
  1686.     if (conn <= 0 || conn >= MAX_USER)
  1687.         return;
  1688.  
  1689.     if (pUser[conn].Mode != USER_PLAY)
  1690.         return;
  1691.  
  1692.     if (pUser[conn].cSock.Sock == 0)
  1693.         return;
  1694.  
  1695.     MSG_SetHpMp sm_shm;
  1696.     memset(&sm_shm, 0, sizeof(MSG_SetHpMp));
  1697.  
  1698.     sm_shm.Type = _MSG_SetHpMp;
  1699.     sm_shm.Size = sizeof(MSG_SetHpMp);
  1700.     sm_shm.ID = conn;
  1701.  
  1702.     sm_shm.Hp = pMob[conn].MOB.CurrentScore.Hp;
  1703.     sm_shm.Mp = pMob[conn].MOB.CurrentScore.Mp;
  1704.  
  1705.     SetReqHp(conn);
  1706.     SetReqMp(conn);
  1707.  
  1708.     //sm_shm.ReqHp = pUser[conn].ReqHp;
  1709.     //sm_shm.ReqMp = pUser[conn].ReqMp;
  1710.  
  1711.  
  1712.     if (!pUser[conn].cSock.AddMessage((char*)&sm_shm, sizeof(MSG_SetHpMp)))
  1713.         CloseUser(conn);
  1714. }
  1715.  
  1716. void SendHpMode(int conn)
  1717. {
  1718.     if (conn <= 0 || conn >= MAX_USER)
  1719.         return;
  1720.  
  1721.     if (pUser[conn].Mode != USER_PLAY)
  1722.         return;
  1723.  
  1724.     if (pUser[conn].cSock.Sock == 0)
  1725.         return;
  1726.  
  1727.     MSG_SetHpMode sm_shmd;
  1728.     memset(&sm_shmd, 0, sizeof(MSG_SetHpMode));
  1729.  
  1730.     sm_shmd.Type = _MSG_SetHpMode;
  1731.     sm_shmd.Size = sizeof(MSG_SetHpMode);
  1732.     sm_shmd.ID = conn;
  1733.  
  1734.     sm_shmd.Hp = pMob[conn].MOB.CurrentScore.Hp;
  1735.     sm_shmd.Mode = pUser[conn].Mode;
  1736.  
  1737.     if (!pUser[conn].cSock.AddMessage((char*)&sm_shmd, sizeof(MSG_SetHpMode)))
  1738.         CloseUser(conn);
  1739. }
  1740.  
  1741. void SendSay(int mob, char *Message)
  1742. {
  1743.     MSG_MessageChat sm_mc;
  1744.     memset(&sm_mc, 0, sizeof(MSG_MessageChat));
  1745.  
  1746.     sm_mc.Type = _MSG_MessageChat;
  1747.     sm_mc.Size = sizeof(MSG_MessageChat);
  1748.     sm_mc.ID = mob;
  1749.  
  1750.     memcpy(sm_mc.String, Message, MESSAGE_LENGTH);
  1751.    
  1752.  
  1753.     GridMulticast(pMob[mob].TargetX, pMob[mob].TargetY, (MSG_STANDARD*)&sm_mc, 0);
  1754. }
  1755.  
  1756. void MapaMulticast(int tx, int ty, MSG_STANDARD *m, int bSend)
  1757. {
  1758.     for (int i = 1; i < MAX_USER; i++)
  1759.     {
  1760.         if (pUser[i].Mode == USER_PLAY && (pMob[i].TargetX / 128) == tx && (pMob[i].TargetY / 128) == ty)
  1761.         {
  1762.             pUser[i].cSock.AddMessage((char*)m, m->Size);
  1763.  
  1764.             if (bSend)
  1765.                 pUser[i].cSock.SendMessageA();
  1766.         }
  1767.     }
  1768. }
  1769.  
  1770. void SendMessageArea(int x1, int y1, int x2, int y2, MSG_STANDARD *m, int bSend)
  1771. {
  1772.     for (int i = 0; i < MAX_USER; i++)
  1773.     {
  1774.         if (pUser[i].Mode != USER_PLAY)
  1775.             continue;
  1776.  
  1777.         if (pMob[i].TargetX >= x1 && pMob[i].TargetY <= x2 && pMob[i].TargetY >= y1 && pMob[i].TargetY <= y2)
  1778.         {
  1779.             pUser[i].cSock.AddMessage((char*)m, m->Size);
  1780.  
  1781.             if (bSend)
  1782.                 pUser[i].cSock.SendMessageA();
  1783.         }
  1784.     }
  1785. }
  1786.  
  1787. void SendSignalParmArea(int x1, int y1, int x2, int y2, int id, unsigned short signal, int parm)
  1788. {
  1789.     for(int x = x1; x < x2; x++)
  1790.     {
  1791.         for(int y = y1; y < y2; y++)
  1792.         {
  1793.             if(x < 0 || x >= MAX_GRIDX || y < 0 || y >= MAX_GRIDY)
  1794.                 continue;
  1795.  
  1796.             int tmob = pMobGrid[y][x];
  1797.  
  1798.             if(tmob >= MAX_USER || tmob == 0)
  1799.                 continue;
  1800.  
  1801.             if(pUser[tmob].Mode != USER_PLAY)
  1802.                 continue;
  1803.  
  1804.             SendClientSignalParm(tmob, id, signal, parm);
  1805.         }
  1806.     }
  1807. }
  1808.  
  1809. void SendShortSignalParm2Area(int x1, int y1, int x2, int y2, int id, unsigned short signal, int parm1, int parm2)
  1810. {
  1811.     for(int x = x1; x < x2; x++)
  1812.     {
  1813.         for(int y = y1; y < y2; y++)
  1814.         {
  1815.             if(x < 0 || x >= MAX_GRIDX || y < 0 || y >= MAX_GRIDY)
  1816.                 continue;
  1817.  
  1818.             int tmob = pMobGrid[y][x];
  1819.  
  1820.             if(tmob >= MAX_USER || tmob == 0)
  1821.                 continue;
  1822.  
  1823.             if(pUser[tmob].Mode != USER_PLAY)
  1824.                 continue;
  1825.  
  1826.             SendClientSignalShortParm2(tmob, id, signal, parm1, parm2);
  1827.         }
  1828.     }
  1829. }
  1830.  
  1831. void SendPKInfo(int conn, int target)
  1832. {
  1833.     if (conn <= 0 || conn >= MAX_USER)
  1834.         return;
  1835.  
  1836.     if (target <= 0 || target >= MAX_USER)
  1837.         return;
  1838.  
  1839.     MSG_STANDARDPARM sm;
  1840.     memset(&sm, 0, sizeof(MSG_STANDARDPARM));
  1841.  
  1842.     sm.Size = sizeof(MSG_STANDARDPARM);
  1843.     sm.Type = _MSG_PKInfo;
  1844.     sm.ID = target;
  1845.  
  1846.     if (NewbieEventServer == 0)
  1847.     {
  1848.         int guilty = GetGuilty(target);
  1849.  
  1850.         int state = 0;
  1851.  
  1852.         if (guilty || pUser[target].PKMode || g_pRvrWar.Status || CastleState || GTorreState)
  1853.             state = 1;
  1854.  
  1855.         sm.Parm = state;
  1856.     }
  1857.     else
  1858.         sm.Parm = 1;
  1859.  
  1860.     pUser[conn].cSock.AddMessage((char*)&sm, sizeof(MSG_STANDARDPARM));
  1861. }
  1862.  
  1863. void SendAffect(int conn)
  1864. {
  1865.     if (conn <= 0 || conn >= MAX_USER)
  1866.         return;
  1867.  
  1868.     MSG_SendAffect sm;
  1869.  
  1870.     memset(&sm, 0, sizeof(MSG_SendAffect));
  1871.  
  1872.     sm.Type = _MSG_SendAffect;
  1873.     sm.Size = sizeof(MSG_SendAffect);
  1874.     sm.ID = conn;
  1875.  
  1876.     for (int i = 0; i < MAX_AFFECT; i++)
  1877.     {
  1878.         if (pMob[conn].Affect[i].Type == 34 && pMob[conn].Affect[i].Level == 1 && pMob[conn].Affect[i].Time >= 32000000)
  1879.         {
  1880.             time_t now;
  1881.             time(&now);
  1882.  
  1883.             if ((pMob[conn].Extra.DivineEnd - now) <= 3600)
  1884.             {
  1885.                 pMob[conn].Affect[i].Time = 450;
  1886.  
  1887.                 sm.Affect[i].Type = pMob[conn].Affect[i].Type;
  1888.                 sm.Affect[i].Value = pMob[conn].Affect[i].Value;
  1889.                 sm.Affect[i].Level = pMob[conn].Affect[i].Level;
  1890.                 sm.Affect[i].Time = pMob[conn].Affect[i].Time;
  1891.  
  1892.                 continue;
  1893.             }
  1894.  
  1895.             if (pMob[conn].Affect[i].Time <= 450)
  1896.                 continue;
  1897.  
  1898.             sm.Affect[i].Type = pMob[conn].Affect[i].Type;
  1899.             sm.Affect[i].Value = pMob[conn].Affect[i].Value;
  1900.             sm.Affect[i].Level = pMob[conn].Affect[i].Level;
  1901.             sm.Affect[i].Time = (int)(((pMob[conn].Extra.DivineEnd - now) / 60 / 60 / 24 * AFFECT_1D) - 1);
  1902.         }
  1903.  
  1904.         else if (pMob[conn].Affect[i].Type >= 1)
  1905.         {
  1906.             sm.Affect[i].Type = pMob[conn].Affect[i].Type;
  1907.             sm.Affect[i].Value = pMob[conn].Affect[i].Value;
  1908.             sm.Affect[i].Level = pMob[conn].Affect[i].Level;
  1909.             sm.Affect[i].Time = pMob[conn].Affect[i].Time;
  1910.         }
  1911.     }
  1912.     pUser[conn].cSock.AddMessage((char*)&sm, sizeof(MSG_SendAffect));
  1913. }
  1914.  
  1915.  
  1916.  
  1917. bool FileExist(const char* Name)
  1918. {
  1919.     if (FILE * file = fopen(Name, "r"))
  1920.     {
  1921.         fclose(file);
  1922.         return true;
  1923.     }
  1924.     return false;
  1925. }
  1926.  
  1927. void SendCounterMob(int clientId, short value, short total)
  1928. {
  1929.     p3BB packet;
  1930.     memset(&packet, 0, sizeof p3BB);
  1931.  
  1932.     packet.Size = sizeof p3BB;
  1933.     packet.Type = 0x3BB;
  1934.     packet.ID = clientId;
  1935.  
  1936.     packet.Value = value;
  1937.     packet.Total = total;
  1938.  
  1939.     pUser[clientId].cSock.AddMessage((char*)&packet, sizeof p3BB);
  1940. }
  1941.  
  1942. char* strFmt(const char* str, ...)
  1943. {
  1944.     static char buffer[512] = { 0, };
  1945.     va_list va;
  1946.     va_start(va, str);
  1947.     vsprintf_s(buffer, str, va);
  1948.     va_end(va);
  1949.     return buffer;
  1950. }
  1951.  
  1952. int ReadBanMac(char* Mac)
  1953. {
  1954.     FILE* arq = NULL;
  1955.     fopen_s(&arq, "Ban/Mac/MacList.txt", "r");
  1956.  
  1957.     if (!arq)
  1958.     {
  1959.         MessageBoxA(0, "Arquivo não encontrado", "Maclist.txt", 0);
  1960.         ExitProcess(1);
  1961.     }
  1962.     char line[100];
  1963.     memset(&line, 0, 100);
  1964.  
  1965.     char mac[25];
  1966.     memset(&mac, 0, 25);
  1967.  
  1968.     while ((fscanf(arq, "%[^\n]", line)) != EOF)
  1969.     {
  1970.         fgetc(arq);
  1971.         sscanf(line, "%s", &mac);
  1972.  
  1973.         if (!strcmp(mac, Mac))
  1974.         {
  1975.             fclose(arq);
  1976.             return 1;
  1977.         }
  1978.     }
  1979.  
  1980.     fclose(arq);
  1981.     return -1;
  1982. }
  1983.  
  1984. void SendBanAccount(int conn, int type)
  1985. {
  1986.     if (conn <= NULL || conn >= MAX_USER)
  1987.         return;
  1988.  
  1989.     struct tm when;
  1990.     time_t now;
  1991.     time(&now);
  1992.     when = *localtime(&now);
  1993.  
  1994.     auto ban = &BannedUser[conn];
  1995.     memset(&BannedUser[conn], 0, sizeof(AccountBanned));
  1996.  
  1997.     switch (type)
  1998.     {
  1999.         /*Temporario 3 horas*/
  2000.     case Banned::Tempo3horas:
  2001.     {
  2002.         ban->mes = when.tm_mon;
  2003.         ban->dia = when.tm_mday;
  2004.         ban->hora = when.tm_hour + 3;
  2005.         ban->min = when.tm_min;
  2006.         ban->ano = when.tm_year;
  2007.         sprintf(temp, "!Conta [%s] bloqueada até as: [%02d:%02d]  de [%02d/%02d/%04d]", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2008.         sprintf(temp, "Nome da conta: [%s] Data de Banimento: [%02d:%02d] de [%02d/%02d/%04d] Motivo: Grade B", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2009.         MyLog(LogType::Banned, pMob[conn].MOB.MobName, temp, 0, pUser[conn].IP);
  2010.         break;
  2011.     }
  2012.  
  2013.     /* 3 dias*/
  2014.     case Banned::Tempo3dias:
  2015.     {
  2016.         ban->mes = when.tm_mon;
  2017.         ban->dia = when.tm_mday + 3;
  2018.         ban->hora = when.tm_hour;
  2019.         ban->min = when.tm_min;
  2020.         ban->ano = when.tm_year;
  2021.         sprintf(temp, "!Conta [%s] bloqueada até as: [%02d:%02d]  de [%02d/%02d/%04d]", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2022.         sprintf(temp, "Nome da conta: [%s] Data de Banimento: [%02d:%02d] de [%02d/%02d/%04d] Motivo: Grade B", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2023.         MyLog(LogType::Banned, pMob[conn].MOB.MobName, temp, 0, pUser[conn].IP);
  2024.         break;
  2025.     }
  2026.  
  2027.     /* 7 dias*/
  2028.     case Banned::Tempo7dias:
  2029.     {
  2030.         ban->mes = when.tm_mon;
  2031.         ban->dia = when.tm_mday + 7;
  2032.         ban->hora = when.tm_hour;
  2033.         ban->min = when.tm_min;
  2034.         ban->ano = when.tm_year;
  2035.         sprintf(temp, "!Conta [%s] bloqueada até as: [%02d:%02d]  de [%02d/%02d/%04d]", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2036.         sprintf(temp, "Nome da conta: [%s] Data de Banimento: [%02d:%02d] de [%02d/%02d/%04d] Motivo: Grade B", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2037.         MyLog(LogType::Banned, pMob[conn].MOB.MobName, temp, 0, pUser[conn].IP);
  2038.         break;
  2039.     }
  2040.  
  2041.     /* 15 dias*/
  2042.     case Banned::Tempo15dias:
  2043.     {
  2044.         ban->mes = when.tm_mon;
  2045.         ban->dia = when.tm_mday + 15;
  2046.         ban->hora = when.tm_hour;
  2047.         ban->min = when.tm_min;
  2048.         ban->ano = when.tm_year;
  2049.         sprintf(temp, "!Conta [%s] bloqueada até as: [%02d:%02d]  de [%02d/%02d/%04d]", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2050.         sprintf(temp, "Nome da conta: [%s] Data de Banimento: [%02d:%02d] de [%02d/%02d/%04d] Motivo: Grade B", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2051.         MyLog(LogType::Banned, pMob[conn].MOB.MobName, temp, 0, pUser[conn].IP);
  2052.         break;
  2053.     }
  2054.  
  2055.     /* 30 dias*/
  2056.     case Banned::Tempo30dias:
  2057.     {
  2058.         ban->mes = when.tm_mon;
  2059.         ban->dia = when.tm_mday + 30;
  2060.         ban->hora = when.tm_hour;
  2061.         ban->min = when.tm_min;
  2062.         ban->ano = when.tm_year;
  2063.         sprintf(temp, "!Conta [%s] bloqueada até as: [%02d:%02d]  de [%02d/%02d/%04d]", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2064.         sprintf(temp, "Nome da conta: [%s] Data de Banimento: [%02d:%02d] de [%02d/%02d/%04d] Motivo: Grade B", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2065.         MyLog(LogType::Banned, pMob[conn].MOB.MobName, temp, 0, pUser[conn].IP);
  2066.         break;
  2067.     }
  2068.  
  2069.     /* Permanente */
  2070.     case Banned::Permanente:
  2071.     {
  2072.         ban->Permanente = TRUE;
  2073.         sprintf(temp, "!Conta [%s] bloqueada até as: [%02d:%02d]  de [%02d/%02d/%04d]", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2074.         sprintf(temp, "Nome da conta: [%s] Data de Banimento: [%02d:%02d] de [%02d/%02d/%04d] Motivo: Grade B", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2075.         MyLog(LogType::Banned, pMob[conn].MOB.MobName, temp, 0, pUser[conn].IP);
  2076.         break;
  2077.     }
  2078.  
  2079.     /* Ban Mac */
  2080.     case Banned::Mac:
  2081.     {
  2082.  
  2083.         FILE* Arquivo;
  2084.         fopen_s(&Arquivo, "Ban/Mac/MacList.txt", "a+");
  2085.  
  2086.         char update[20];
  2087.         memset(update, 0, 20);
  2088.  
  2089.         sprintf(update, "%s \n", pUser[conn].Mac);
  2090.  
  2091.         fputs(update, Arquivo);
  2092.         fclose(Arquivo);
  2093.         break;
  2094.     }
  2095.  
  2096.     /* Ban Analise */
  2097.     case Banned::Analise:
  2098.     {
  2099.  
  2100.         ban->Analyze = TRUE;
  2101.         sprintf(temp, "!Conta [%s] bloqueada até as: [%02d:%02d]  de [%02d/%02d/%04d]", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2102.         sprintf(temp, "Nome da conta: [%s] Data de Banimento: [%02d:%02d] de [%02d/%02d/%04d] Motivo: Grade B", pUser[conn].AccountName, ban->hora, ban->min, ban->dia, ban->mes + 1, ban->ano + 1900);
  2103.         MyLog(LogType::Banned, pMob[conn].MOB.MobName, temp, 0, pUser[conn].IP);
  2104.         break;
  2105.     }
  2106.  
  2107.    
  2108.     }
  2109.     SendSaveBanned(conn);
  2110.     SendClientMsg(conn, temp);
  2111.     CloseUser(conn);
  2112.  
  2113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement