common.cpp
上传用户:garry_shen
上传日期:2015-04-15
资源大小:45647k
文件大小:3k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include "StreamSocket.h"
  4. #include "Common.h"
  5. #include "wsa_xtra.h"
  6. #include "../Common.h"
  7. #include "../xmudos.h"
  8. extern rmfullglobals myglobs;
  9. PlayerName *playerStartHead=NULL;
  10. PlayerName *playerEndHead=NULL;
  11. int iNumStart=0;
  12. int iNumEnd=0;
  13. CRITICAL_SECTION csPlayerStart;
  14. CRITICAL_SECTION csPlayerEnd;
  15. extern int g_iActiveClientNum;
  16. extern char g_tszPathName[256];
  17. StreamSocket sockListen;
  18. void InitPlayer(HWND hwnd)
  19. {
  20. SetTimer(hwnd,7,1000,NULL);
  21. InitializeCriticalSection(&csPlayerStart);
  22. InitializeCriticalSection(&csPlayerEnd);
  23. }
  24. void ReleaseNet()
  25. {
  26. EnterCriticalSection(&csPlayerStart);
  27. EnterCriticalSection(&csPlayerEnd);
  28. sockListen.closeing();
  29. DeleteStartList();
  30. DeleteEndList();
  31. LeaveCriticalSection(&csPlayerEnd);
  32. LeaveCriticalSection(&csPlayerStart);
  33. }
  34. BOOL Add_UserStart(char *szUser)
  35. {
  36. int iLen=strlen(szUser)+1;
  37. if(iLen<=1)
  38. return TRUE;
  39. EnterCriticalSection(&csPlayerStart);
  40. PlayerName *playerNew;
  41. if(NULL!=(playerNew=new PlayerName)){
  42. if(NULL!=(playerNew->lpstrName=new char[iLen])){
  43. strcpy(playerNew->lpstrName,szUser);
  44. playerNew->next=NULL;
  45. if(iNumStart==0)
  46. playerStartHead=playerNew;
  47. else{
  48. playerNew->next=playerStartHead;
  49. playerStartHead=playerNew;
  50. }
  51. iNumStart++;
  52. LeaveCriticalSection(&csPlayerStart);
  53. return TRUE;
  54. }else
  55. delete playerNew;
  56. }
  57. LeaveCriticalSection(&csPlayerStart);
  58. return FALSE;
  59. }
  60. BOOL Add_UserEnd(char *szUser)
  61. {
  62. int iLen=strlen(szUser)+1;
  63. if(iLen<=1) return TRUE;
  64. iLen++;
  65. EnterCriticalSection(&csPlayerEnd);
  66. PlayerName *playerNew;
  67. if(NULL!=(playerNew=new PlayerName)){
  68. if(NULL!=(playerNew->lpstrName=new char[iLen])) {
  69. strcpy(playerNew->lpstrName,szUser);
  70. playerNew->next=NULL;
  71. if(iNumEnd==0)
  72. playerEndHead=playerNew;
  73. else{
  74. playerNew->next=playerEndHead;
  75. playerEndHead=playerNew;
  76. }
  77. iNumEnd++;
  78. LeaveCriticalSection(&csPlayerEnd);
  79. return TRUE;
  80. }else
  81. delete playerNew;
  82. }
  83. LeaveCriticalSection(&csPlayerEnd);
  84. return FALSE;
  85. }
  86. void DeleteStartList()
  87. {
  88. PlayerName *playerTemp;
  89. while(playerStartHead){
  90. playerTemp=playerStartHead->next;
  91. if(playerStartHead->lpstrName)
  92. delete[] playerStartHead->lpstrName;
  93. delete playerStartHead;
  94. playerStartHead=playerTemp;
  95. }
  96. }
  97. void DeleteEndList()
  98. {
  99. PlayerName *playerTemp;
  100. while(playerEndHead){
  101. playerTemp=playerEndHead->next;
  102. if(playerEndHead->lpstrName)
  103. delete[] playerEndHead->lpstrName;
  104. delete playerEndHead;
  105. playerEndHead=playerTemp;
  106. }
  107. }