RenegadeGR.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // RenegadeGR.cpp : Defines the entry point for the DLL application.
  19. //
  20. #include <malloc.h>
  21. #include <string.h>
  22. #include "jni.h"
  23. #include "RenegadeGR.h"
  24. #include "RenegadeNet.h"
  25. #include "rengameres.h"
  26. #include "tcpmgr.h"
  27. #include "tcpcon.h"
  28. JNIEXPORT jint JNICALL Java_RenegadeNet__1nativeSendGR
  29. (JNIEnv* env, jclass cls, jobjectArray loginArray, jdoubleArray scoreArray)
  30. {
  31. int i = 0;
  32. char** packetLogins = NULL;
  33. double* packetScores = NULL;
  34. // Build packetLogins array
  35. jsize loginlen = env->GetArrayLength(loginArray);
  36. packetLogins = new char*[loginlen];
  37. for(i = 0; i < loginlen; i++)
  38. {
  39. jstring jstr = (jstring)env->GetObjectArrayElement(loginArray, i);
  40. const char *str = env->GetStringUTFChars(jstr, 0);
  41. packetLogins[i] = new char[strlen(str)+1];
  42. strcpy(packetLogins[i], str);
  43. env->ReleaseStringUTFChars(jstr, str);
  44. }
  45. // Build packetScores array
  46. jsize scorelen = env->GetArrayLength(scoreArray);
  47. jdouble *jscores = env->GetDoubleArrayElements(scoreArray, 0);
  48. packetScores = new double[scorelen];
  49. for (i = 0; i < scorelen; i++)
  50. packetScores[i] = jscores[i];
  51. env->ReleaseDoubleArrayElements(scoreArray, jscores, 0);
  52. RenegadeGameRes renegadeGameRes("10.2.20.28", 4850);
  53. //RenegadeGameRes renegadeGameRes;
  54. renegadeGameRes.setGameID(21450402);
  55. renegadeGameRes.setPlayerCount((unsigned char)loginlen);
  56. renegadeGameRes.setClanGame(0);
  57. renegadeGameRes.setDuration(100);
  58. renegadeGameRes.setMapName("Renegade Map");
  59. renegadeGameRes.setSKU(GR_ENGLISH);
  60. renegadeGameRes.setStyle(GR_DEATHMATCH);
  61. renegadeGameRes.setNumClans(0);
  62. renegadeGameRes.setStartTime(100);
  63. renegadeGameRes.setTournament(1);
  64. for(i = 0; i < loginlen; i++)
  65. {
  66. renegadeGameRes.addPlayer(packetLogins[i], packetScores[i], 0, 245, 0, 5, 5, 3, 244);
  67. }
  68. int sendlen = renegadeGameRes.sendResults();
  69. delete[] packetScores;
  70. for(i = 0; i < loginlen; i++)
  71. delete[] (packetLogins[i]);
  72. delete[] packetLogins;
  73. return sendlen;
  74. }
  75. JNIEXPORT void JNICALL Java_RenegadeNet_startWinSock(JNIEnv *, jclass)
  76. {
  77. WORD wVersionRequested;
  78. WSADATA wsaData;
  79. int err = 1;
  80. wVersionRequested = MAKEWORD(1, 1);
  81. err = WSAStartup( wVersionRequested, &wsaData);
  82. /*if (err != 0)
  83. {
  84. LOG_END("failed");
  85. //assert(false);
  86. }
  87. else
  88. {
  89. LOG_END("ok");
  90. }*/
  91. }
  92. JNIEXPORT void JNICALL Java_RenegadeNet_stopWinSock(JNIEnv *, jclass)
  93. {
  94. WSACleanup();
  95. }