Guest User

Untitled

a guest
Dec 11th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.21 KB | None | 0 0
  1. /*********************************************************************
  2. * title_name        : Auto Notice System
  3. * date_created      : 2017.11.01
  4. * filename          : AutoNotice.cpp
  5. * author            : TreeN
  6. * version           : Version 0.0.1
  7. */
  8.  
  9. #include "stdafx.h"
  10. #include <string>
  11. #include <fstream>
  12. #include <algorithm>
  13. #include <iostream>
  14. #include "utils.h"
  15. #include "config.h"
  16. #include "constants.h"
  17. #include "char.h"
  18.  
  19. #ifdef ENABLE_AUTO_NOTICE
  20. #include "AutoNotice.h"
  21.  
  22. CAutoNotice::CAutoNotice()
  23. {
  24. }
  25.  
  26. CAutoNotice::~CAutoNotice()
  27. {
  28. }
  29.  
  30. void CAutoNotice::SendNoticeLine(const char * format, ...)
  31. {
  32.     if (!format)
  33.         return;
  34.  
  35.     char chatbuf[CHAT_MAX_LEN + 1];
  36.     va_list args;
  37.  
  38.     va_start(args, format);
  39.     vsnprintf(chatbuf, sizeof(chatbuf), format, args);
  40.     va_end(args);
  41.  
  42.     SendNotice(chatbuf);
  43. }
  44.  
  45. void CAutoNotice::Check(int day, int hour, int minute, int second)
  46. {
  47.     HourlyAnnouncement(minute, second);
  48.     SpecialHourAnnoucement(day, hour, minute, second);
  49.     TimeIntervalAnnoucement(day, hour, minute, second);
  50. }
  51.  
  52. void CAutoNotice::HourlyAnnouncement(int minute, int second)
  53. {
  54.     if (AutoNoticeSettings::ENABLE_HOURLY_ANNOUCEMENT == false)
  55.         return;
  56.  
  57.     if (second != 00)
  58.         return;
  59.  
  60.     if (AutoNoticeSettings::HOURLY_MINUTE == minute)
  61.     {
  62.         // to create new line of message simply add new SendNoticeLine function here
  63.  
  64.         SendNoticeLine("Don't feed the yangsellers. Buying from the bots damage the");
  65.         SendNoticeLine("server economy, spoils gameplay and you will end your game banned for it!");
  66.         SendNoticeLine("Visit our webpages! www.servername.com | ts3.servername.com | forum.servername.com ");
  67.     }
  68. }
  69.  
  70. void CAutoNotice::SpecialHourAnnoucement(int day, int hour, int minute, int second)
  71. {
  72.     if (AutoNoticeSettings::ENABLE_SPECIAL_HOUR_ANNOUCEMENT == false)
  73.         return;
  74.  
  75.     if (second != 00)
  76.         return;
  77.  
  78.     // when you add new hours to first table(or delete) please add(or delete) messages from szpNoticeText.
  79.     /*
  80.         MONDAY = 1,
  81.         TUESDAY = 2,
  82.         WEDNESDAY = 3,
  83.         THURSDAY = 4,
  84.         FRIDAY = 5,
  85.         SATURDAY = 6,
  86.         SUNDAY = 0,
  87.  
  88.         EVERYDAY = 100,
  89.     */
  90.     // if you add new notices please fix the table size
  91.     // example of showing notice
  92.     // notice from szpNoticeHours[0] will appear in Monday at 19:00 and shows 2 lines
  93.     int szpNoticeHours[][3] =
  94.     {
  95.         { 19, 00, MONDAY },
  96.         { 20, 00, WEDNESDAY },
  97.         { 21, 00, EVERYDAY }
  98.     };
  99.  
  100.     // maximum 5 lines of notice at once, if you set "" then this notice line not appear
  101.     const int MAX_NOTICE_LINE = 5;
  102.     char* szpNoticeText[][MAX_NOTICE_LINE] =
  103.     {
  104.         { "Today from 19:00 to 19:30 we have sales in our ItemShop", "Open Ingame Itemshop and check new prices!", "", "", "" },                        //szpNoticeHours[0]
  105.         { "Hmm did you saw a cheater? ", "Yes? Fantastic! Please open Ticket Menager", "and send a ticket to us", "Thank you for your help.", "" },     //szpNoticeHours[1]
  106.         { "The best server ", "of 2017", "is ServerName", "visit our web pages", "www.servername.com | www.forum.servername.com" }                      //szpNoticeHours[2]
  107.     };
  108.  
  109.     for (int i = 0; i < _countof(szpNoticeHours); i++)
  110.     {
  111.         if ((hour == szpNoticeHours[i][0] && minute == szpNoticeHours[i][1]))
  112.         {
  113.             if (szpNoticeHours[i][2] != EVERYDAY)
  114.                 if (day != szpNoticeHours[i][2])
  115.                     continue;
  116.  
  117.             for (int j = 0; j < MAX_NOTICE_LINE; j++)
  118.             {
  119.                 if (szpNoticeText[i][j] == "")
  120.                     continue;
  121.  
  122.                 SendNoticeLine(szpNoticeText[i][j]);
  123.             }
  124.         }
  125.     }
  126. }
  127.  
  128. void CAutoNotice::TimeIntervalAnnoucement(int day, int hour, int minute, int second)
  129. {
  130.     if ((bool)AutoNoticeSettings::ENABLE_TIME_INTERVAL_ANNOUCEMENT == false)
  131.         return;
  132.  
  133.     if (second != 00)
  134.         return;
  135.  
  136.     // when you add new hours to first table(or delete) please add(or delete) messages from szpNoticeText.
  137.     /*
  138.     MONDAY = 1,
  139.     TUESDAY = 2,
  140.     WEDNESDAY = 3,
  141.     THURSDAY = 4,
  142.     FRIDAY = 5,
  143.     SATURDAY = 6,
  144.     SUNDAY = 0,
  145.  
  146.     EVERYDAY = 100,
  147.     */
  148.     // if you add new notices please fix the table size
  149.     // this notices shows every 20 minutes
  150.     // example of showing notice
  151.     // notice from szpNoticeHours[0] will appear in Monday at 19:00 and 19:20 and shows 2 lines
  152.     int szpNoticeHours[][5] =
  153.     {
  154.         { 19, 00,       19, 30,     MONDAY },
  155.         { 20, 00,       20, 45,     TUESDAY },
  156.         { 21, 00,       23, 30,     EVERYDAY },
  157.     };
  158.  
  159.     // maximum 5 lines of notice at once, if you set "" then notice not appear
  160.     const int MAX_NOTICE_LINE = 5;
  161.     char* szpNoticeText[][MAX_NOTICE_LINE] =
  162.     {
  163.         { "Special Time Notice 1.1", "Special Time Notice 1.2", "", "", "" },                       //szpNoticeHours[0]
  164.         { "Special Time Notice 2.1", "Special Time Notice 2.2", "Special Time Notice 2.3", "Special Time Notice 2.4", "" }, //szpNoticeHours[1]
  165.         { "Special Time Notice 3.1", "Special Time Notice 3.2", "Special Time Notice 3.3", "Special Time Notice 3.4", "Special Time Notice 3.5 | Special Time Notice 3.5" }                     //szpNoticeHours[2]
  166.     };
  167.  
  168.     for (int i = 0; i < _countof(szpNoticeHours); i++)
  169.     {
  170.         if ((hour >= szpNoticeHours[i][0] && minute >= szpNoticeHours[i][1]) && (hour <= szpNoticeHours[i][2] && minute <= szpNoticeHours[i][3])
  171.             && (minute == 00 || minute == 20 || minute == 40))
  172.         {
  173.             if (szpNoticeHours[i][4] != EVERYDAY && day != szpNoticeHours[i][4])
  174.                 continue;
  175.  
  176.             for (int j = 0; j < MAX_NOTICE_LINE; j++)
  177.             {
  178.                 if (szpNoticeText[i][j] == "")
  179.                     continue;
  180.  
  181.                 SendNoticeLine(szpNoticeText[i][j]);
  182.             }
  183.         }
  184.     }
  185. }
  186.  
  187. #endif
Advertisement
Add Comment
Please, Sign In to add comment