ODStat.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* OpenDoors Online Software Programming Toolkit
  2. * (C) Copyright 1991 - 1999 by Brian Pirie.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. *
  19. * File: ODStat.c
  20. *
  21. * Description: Helper functions used by various built-in personalities.
  22. *
  23. * Revisions: Date Ver Who Change
  24. * ---------------------------------------------------------------
  25. * Oct 13, 1994 6.00 BP New file header format.
  26. * Dec 09, 1994 6.00 BP Standardized coding style.
  27. * Jul 18, 1995 6.00 BP Fix ODStatGetUserAge() bug.
  28. * Nov 13, 1995 6.00 BP 32-bit portability.
  29. * Nov 13, 1995 6.00 BP Created odstat.h.
  30. * Nov 16, 1995 6.00 BP Removed oddoor.h, added odcore.h.
  31. * Jan 12, 1996 6.00 BP Added ODStatStartArrowUse(), etc.
  32. * Feb 19, 1996 6.00 BP Changed version number to 6.00.
  33. * Mar 03, 1996 6.10 BP Begin version 6.10.
  34. * Mar 13, 1996 6.10 BP bOnlyShiftArrow -> nArrowUseCount.
  35. * Mar 19, 1996 6.10 BP MSVC15 source-level compatibility.
  36. * Aug 10, 2003 6.23 SH *nix support
  37. */
  38. #define BUILDING_OPENDOORS
  39. #include <string.h>
  40. #include <ctype.h>
  41. #include <stddef.h>
  42. #include <stdlib.h>
  43. #include <time.h>
  44. #include <stdio.h>
  45. #include "OpenDoor.h"
  46. #include "ODCore.h"
  47. #include "ODGen.h"
  48. #include "ODStat.h"
  49. #include "ODKrnl.h"
  50. /* Global working string available to all personalities for status line */
  51. /* generation. */
  52. char szStatusText[80];
  53. /* ----------------------------------------------------------------------------
  54. * ODStatAddKey()
  55. *
  56. * Adds another hot key to the array of custom local keys.
  57. *
  58. * Parameters: wKeyCode - IBM scan-code/ASCII-code style key identification
  59. * code to add.
  60. *
  61. * Return: void
  62. */
  63. void ODStatAddKey(WORD wKeyCode)
  64. {
  65. if(od_control.od_num_keys < 16)
  66. od_control.od_hot_key[od_control.od_num_keys++] = wKeyCode;
  67. }
  68. /* ----------------------------------------------------------------------------
  69. * ODStatRemoveKey()
  70. *
  71. * Removes a custom sysop hotkey that was previously added with ODStatAddKey().
  72. *
  73. * Parameters: wKeyCode - The scan code / ASCII code key identification code
  74. * to remove.
  75. *
  76. * Return: void
  77. */
  78. void ODStatRemoveKey(WORD wKeyCode)
  79. {
  80. INT nCount;
  81. for(nCount = 0; nCount < od_control.od_num_keys; ++nCount)
  82. if((WORD)od_control.od_hot_key[nCount] == wKeyCode)
  83. {
  84. if(nCount != od_control.od_num_keys - 1)
  85. {
  86. od_control.od_hot_key[nCount] =
  87. od_control.od_hot_key[od_control.od_num_keys-1];
  88. }
  89. --od_control.od_num_keys;
  90. return;
  91. }
  92. }
  93. /* ----------------------------------------------------------------------------
  94. * ODStatGetUserAge()
  95. *
  96. * Generates a string containing the age, in years, of the current
  97. * user, based on the current date and the user's birthday.
  98. *
  99. * Parameters: pszAge - Pointer to a string where user's age should be stored.
  100. *
  101. * Return: void
  102. */
  103. void ODStatGetUserAge(char *pszAge)
  104. {
  105. INT nAge;
  106. INT n;
  107. time_t Time;
  108. struct tm *TimeBlock;
  109. if(od_control.od_info_type==RA2EXITINFO || od_control.od_info_type==DOORSYS_WILDCAT)
  110. {
  111. nAge = atoi(od_control.user_birthday) - 1;
  112. if(strlen(od_control.user_birthday) == 8 && nAge <= 11)
  113. {
  114. if(od_control.user_birthday[6] >= '0'
  115. && od_control.user_birthday[6] <= '9'
  116. && od_control.user_birthday[7] >= '0'
  117. && od_control.user_birthday[7] <= '9')
  118. {
  119. if(od_control.user_birthday[3] >= '0'
  120. && od_control.user_birthday[3] <= '3'
  121. && od_control.user_birthday[4] >= '0'
  122. && od_control.user_birthday[4] <= '9')
  123. {
  124. Time = time(NULL);
  125. TimeBlock = localtime(&Time);
  126. n = (TimeBlock->tm_year % 100)
  127. - atoi((char *)od_control.user_birthday + 6);
  128. if(n < 0) nAge = n + 100; else nAge = n;
  129. n = atoi(od_control.user_birthday) - 1;
  130. if(TimeBlock->tm_mon < n)
  131. --nAge;
  132. else if(TimeBlock->tm_mon == n)
  133. {
  134. n=atoi((char *)od_control.user_birthday + 3);
  135. if(TimeBlock->tm_mday < n) --nAge;
  136. }
  137. sprintf(pszAge, "%d", nAge);
  138. return;
  139. }
  140. }
  141. }
  142. }
  143. strcpy(pszAge, "?");
  144. }
  145. /* ----------------------------------------------------------------------------
  146. * ODStatStartArrowUse()
  147. *
  148. * Called by OpenDoors when it needs to use the arrow keys, and so they
  149. * shouldn't be used by the status line.
  150. *
  151. * Parameters: None
  152. *
  153. * Return: void
  154. */
  155. void ODStatStartArrowUse(void)
  156. {
  157. ++nArrowUseCount;
  158. }
  159. /* ----------------------------------------------------------------------------
  160. * ODStatEndArrowUse()
  161. *
  162. * Called by OpenDoors when it no longer needs to use the arrow keys, and so
  163. * they can again be used by the status line.
  164. *
  165. * Parameters: None
  166. *
  167. * Return: void
  168. */
  169. void ODStatEndArrowUse(void)
  170. {
  171. ASSERT(nArrowUseCount > 0);
  172. --nArrowUseCount;
  173. }