in insim 5 IS_MTC was modifed and i add this code in my CInsim class
struct IS_MTC // Msg To Connection - hosts only - send to a connection / a player / all { byte Size; // 8 + TEXT_SIZE (TEXT_SIZE = 4, 8, 12... 128) byte Type; // ISP_MTC byte ReqI; // 0 byte Sound; // sound effect (see Message Sounds below) byte UCID; // connection's unique id (0 = host / 255 = all) byte PLID; // player's unique id (if zero, use UCID) byte Sp2; byte Sp3; // char Text[TEXT_SIZE]; // up to 128 characters of text - last byte must be zero };
function with error protection
but a have problems if strlen > 123
/** * Send a variable sized message to connect */ bool CInsim::send_mtc(void* s_mst, char *errmsg) { struct IS_MTC *pack_mtc = (struct IS_MTC*)s_mst; int text_len = strlen(pack_mtc->Msg); int text2send; if (text_len == 0) { strcpy(errmsg,"strlen == 0"); return false; } else if (text_len > 127) { strcpy(errmsg,"strlen > 127"); return false; } text2send = text_len + 4 - text_len%4; // 4, 8 ,12, ..., 128 pack_mtc->Size = 8 + text2send; pthread_mutex_lock (&ismutex); if (send(sock, (const char *)pack_mtc, pack_mtc->Size, 0) < 0) { pthread_mutex_unlock (&ismutex); strcpy(errmsg,"can't send mtc"); return false; } pthread_mutex_unlock (&ismutex); return true; }
Last edited by denis-takumi, Mon 25 Apr 2011, 07:05 .