tcpObject_ScriptBinding.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. ConsoleMethodGroupBeginWithDocs(TCPObject, SimObject)
  23. /*! Use the send method to send any number of parameters, as strings, one at a time to the agent at the other end of the connection.
  24. @param ... Any number of arguments, as strings. Each string is sent separately. i.e. The arguments are not concatenated.
  25. @return No return value
  26. */
  27. ConsoleMethodWithDocs( TCPObject, send, ConsoleVoid, 3, 0, ( ... ))
  28. {
  29. for(S32 i = 2; i < argc; i++)
  30. object->send((const U8 *) argv[i], dStrlen(argv[i]));
  31. }
  32. /*! Use the listen method to allow this TCPObject to accept connections on the specified port.
  33. @param port A value between 1000 and 65536.
  34. @return No return value
  35. */
  36. ConsoleMethodWithDocs( TCPObject, listen, ConsoleVoid, 3, 3, ( port ))
  37. {
  38. object->listen(U32(dAtoi(argv[2])));
  39. }
  40. /*! Use the connect method to request a connection to a remote agent at the address addr.
  41. @param addr A string containing an address of the form: ?A.B.C.D:Port?, where A .. B are standard IP numbers between 0 and 255 and Port can be between 1000 and 65536.
  42. @return No return value.
  43. @sa disconnect
  44. */
  45. ConsoleMethodWithDocs( TCPObject, connect, ConsoleVoid, 3, 3, ( addr ))
  46. {
  47. object->connect(argv[2]);
  48. }
  49. //Luma: Used to force networking to be opened before connecting... written specifically to handle GPRS/EDGE/3G situation on iPhone, but can be expanded to other platforms too
  50. /*!
  51. Connect to the given address, making sure that the connection is open first.
  52. */
  53. ConsoleMethodWithDocs( TCPObject, openAndConnect, ConsoleVoid, 3, 3, (string addr))
  54. {
  55. object->openAndConnect(argv[2]);
  56. }
  57. /*! Use the disconnect method to close a previously opened connection without destroying the requesting TCPOpbject.
  58. This will close any open connection, but not destroy this object. Thus, the object can be used to open a new connection.
  59. @return No return value.
  60. @sa connect
  61. */
  62. ConsoleMethodWithDocs( TCPObject, disconnect, ConsoleVoid, 2, 2, ())
  63. {
  64. object->disconnect();
  65. }
  66. //Luma: Encode data before sending via TCP so that only valid URL characters are sent
  67. /*! Performs URLEncoding on a single string.
  68. */
  69. ConsoleMethodWithDocs(TCPObject, URLEncodeString, ConsoleString, 3, 3, (string data))
  70. {
  71. U8 *pEncodedString;
  72. U32 iNewBufferLen;
  73. pEncodedString = object->URLEncodeData((U8 *)argv[2], dStrlen(argv[2]) + 1, &iNewBufferLen);
  74. //copy string to return buffer
  75. char *pcReturnBuffer = Con::getReturnBuffer(iNewBufferLen);
  76. dMemcpy(pcReturnBuffer, pEncodedString, iNewBufferLen);
  77. //free encoded data pointer
  78. dFree((void *)pEncodedString);
  79. return pcReturnBuffer;
  80. }
  81. ConsoleMethodGroupEndWithDocs(TCPObject)