Ejemplo n.º 1
0
    IEnumerator handle_connect(Custom_msg_type _type, Message_obj msg, int len, int conn_id, int host, int channel_id, byte[] raw_msg)
    {
        switch (_type)
        {
        case Custom_msg_type.CREATE_PLAYER:
            string name_create           = msg.arg1;
            string hashedpassword_create = msg.arg2;

            pm.create_player(name_create, hashedpassword_create);
            break;

        case Custom_msg_type.LOGIN:
            string name            = msg.arg1;
            string hashed_password = msg.arg2;
            print($"login as name {name} and pass {hashed_password}");

            if (!pm.login_player(name, hashed_password, conn_id))
            {
                print("didn't add them");
            }
            //print("logged in");
            break;

        case Custom_msg_type.SEND_PLAYER_LIST:
            //out
            //need a action that sends pm.player_table and pm.party_table

            //              scatch this one

            //pm.inform_lobby_players

            break;

        case Custom_msg_type.LEAVE_PARTY:
            pm.leave_party(conn_id);
            break;

        case Custom_msg_type.REQ_JOIN_PARTY:
            print("request join");
            //requestee
            //action that send request msg
            int requestee = 0;
            if (msg.arg1 != "")
            {
                requestee = pm.get_conn_id(msg.arg1);
            }
            else
            {
                requestee = msg.target_connection;
            }


            print(pm.request_join(conn_id, requestee, send_action(_type, conn_id, requestee, channel_id, host)));
            //pm.request_join
            break;

        case Custom_msg_type.INVITE_PLAYER:
            //invitee
            //action that sends invite msg
            int invitee = 0;
            if (msg.arg1 != "")
            {
                invitee = pm.get_conn_id(msg.arg1);
            }
            else
            {
                invitee = msg.target_connection;
            }
            pm.invite_player(conn_id, invitee, send_action(_type, conn_id, invitee, channel_id, host));


            //pm.invite_player
            break;

        case Custom_msg_type.START_GAME:
            //action that sends start game msg to clients


            pm.start_game(conn_id, start_end_action(Custom_msg_type.START_GAME, channel_id, host));
            //pm.start_game
            break;

        case Custom_msg_type.END_GAME:

            pm.end_game(conn_id, start_end_action(Custom_msg_type.END_GAME, channel_id, host));
            break;

        case Custom_msg_type.LOGOUT:
            print($"loging out {conn_id}");
            pm.logout_player(conn_id);
            break;

        case Custom_msg_type.MTC:
            pm.multicast(conn_id, forward(channel_id, host, raw_msg));
            break;

        case Custom_msg_type.RPC:
            pm.rpc(conn_id, forward(channel_id, host, raw_msg));
            break;

        case Custom_msg_type.CMD:
            pm.command(conn_id, forward(channel_id, host, raw_msg));
            break;
        }
        //print("leaving handle");
        yield return(null);
        //print("back in handle");
    }
Ejemplo n.º 2
0
    void handle_connect(Custom_msg_type _type, Message_obj msg, int len, int conn_id, int host, int channel_id, byte[] raw_msg)
    {
        switch (_type)
        {
        case Custom_msg_type.CREATE_PLAYER:
            string name_create           = msg.arg1;
            string hashedpassword_create = msg.arg2;

            if (pm.create_player(name_create, hashedpassword_create))
            {
                send_action(Custom_msg_type.CREATE_PLAYER, 1, conn_id, channel_id, host)();
            }
            else
            {
                send_action(Custom_msg_type.CREATE_PLAYER, 0, conn_id, channel_id, host)();
            }

            break;

        case Custom_msg_type.LOGIN:
            string name            = msg.arg1;
            string hashed_password = msg.arg2;
            GAME   title           = (GAME)msg.target_connection;
            print($"login as name {name} and pass {hashed_password} @ {conn_id}");
            Tuple <bool, List <string> > pi = pm.login_player(name, hashed_password, conn_id, title);
            if (!pi.Item1)
            {
                send_action(Custom_msg_type.LOGIN, 0, conn_id, channel_id, host)();
            }
            else
            {
                foreach (string friend in pi.Item2)
                {
                    send_action(Custom_msg_type.GET_FRIEND, 0, conn_id, channel_id, host, friend)();
                }
                send_action(Custom_msg_type.LOGIN, 1, conn_id, channel_id, host)();
            }
            break;

        case Custom_msg_type.SEND_PLAYER_LIST:
            //out
            //need a action that sends pm.player_table and pm.party_table

            //              scatch this one

            //pm.inform_lobby_players

            break;

        case Custom_msg_type.LEAVE_PARTY:
            pm.leave_party(conn_id);
            break;

        case Custom_msg_type.REQ_JOIN_PARTY:
            print("request join");
            //requestee
            //action that send request msg
            int requestee = 0;
            if (msg.arg1 != "")
            {
                requestee = pm.get_conn_id(msg.arg1);
            }
            else
            {
                requestee = msg.target_connection;
            }


            print(pm.request_join(conn_id, requestee, send_action(_type, conn_id, requestee, channel_id, host)));
            //pm.request_join
            break;

        case Custom_msg_type.INVITE_PLAYER:
            //invitee
            //action that sends invite msg
            int invitee = 0;
            if (msg.arg1 != "")
            {
                invitee = pm.get_conn_id(msg.arg1);
            }
            else
            {
                invitee = msg.target_connection;
            }
            pm.invite_player(conn_id, invitee, send_action(_type, conn_id, invitee, channel_id, host));


            //pm.invite_player
            break;

        case Custom_msg_type.START_GAME:
            //action that sends start game msg to clients

            print($"{conn_id} is trying to start a game");
            pm.start_game(conn_id, start_end_action(Custom_msg_type.START_GAME, channel_id, host));
            //pm.start_game
            break;

        case Custom_msg_type.END_GAME:

            pm.end_game(conn_id, start_end_action(Custom_msg_type.END_GAME, channel_id, host));
            break;

        case Custom_msg_type.FIND_MATCH:
            pm.find_match(conn_id);
            start_end_action(Custom_msg_type.FIND_MATCH, channel_id, conn_id);
            break;

        case Custom_msg_type.LOGOUT:
            print($"loging out {conn_id}");
            pm.logout_player(conn_id);
            break;

        case Custom_msg_type.MTC:
            pm.multicast(conn_id, forward(channel_id, host, raw_msg));
            break;

        case Custom_msg_type.RPC:
            pm.rpc(conn_id, forward(channel_id, host, raw_msg));
            break;

        case Custom_msg_type.CMD:
            pm.command(conn_id, forward(channel_id, host, raw_msg));
            break;

        case Custom_msg_type.SEND_PARTY_LIST:
            break;

        case Custom_msg_type.ADD_FRIEND:
            print($"{conn_id} wants to friend {msg.arg1}");
            Tuple <bool, int> pi2 = pm.send_friend_request(conn_id, msg.arg1);
            if (pi2.Item1)
            {
                send_action(Custom_msg_type.ADD_FRIEND, 1, conn_id, channel_id, host)();
                if (pi2.Item2 != -1)
                {
                    print($"{pi2.Item2} is online");
                    send_action(Custom_msg_type.GET_FRIEND, conn_id, pm.get_conn_id(msg.arg1), channel_id, host)();
                }
            }
            else
            {
                send_action(Custom_msg_type.ADD_FRIEND, 0, conn_id, channel_id, host)();
            }
            break;

        case Custom_msg_type.GET_PLAYER_INFO:
            forward(large_data_channel, host, pm.player_data(host))(new List <int>()
            {
                conn_id
            });
            break;

        case Custom_msg_type.SET_PLAYER_INFO:
            pm.set_player_data(conn_id, raw_msg);
            break;
        }
    }