Example #1
0
    void caseLogin() {
        int id=readbyte(0);
        Player player = players.get(id);
        player->name = readstring(0);
        cout << "Player: " << player->name << " joined." << endl;
        clearbuffer(0);
        writebyte(3,0);
        writebyte(id,0);

    /*const char* name_1=player->name.c_str();
    char* name=const_cast<char*>(name_1);*/
    //^ string to char* conversion... change it to:   &(player->name)[0]
        writestring(&(player->name)[0],0);
        sendAll(player);

        for(auto it : players)
            if((it->second) != player) {
                clearbuffer(0);
                writebyte(3,0);
                writebyte((it->second)->id,0);
                writestring(&(it->second->name)[0],0);
                sendmessage(it->second->sock, "", 0, 0);
            }

        }
Example #2
0
        void caseLeave() {
            int id=readbyte(0);
            Player player = players.get(id);

            cout << player->name << " has left." << endl;

            clearbuffer(0);
            writebyte(6,0);
            writebyte(id,0);
            writestring(&(player->name)[0],0);
            sendAll(player);

            closesock(player->sock);
        }
Example #3
0
        void caseEnter() {
            int id=readbyte(0);
            Player player = players.get(id);

            player->x = readshort(0);
            player->y = readshort(0);
            player->direction = readshort(0);

            clearbuffer(0);
            writebyte(5,0);
            writebyte(id,0);
            writeshort(player->x,0);
            writeshort(player->y,0);
            writeshort(player->direction,0);
            sendAll(player);
        }