Esempio n. 1
0
    void handleInit(string message)
    {
        SCInit m = JsonUtility.FromJson <SCInit>(message);

        switch (m.sub)
        {
        case SCInit.SubType.Init:
            player = m.player;                                                                   // Set player number to be sent to server in all subsequent messages
            break;

        case SCInit.SubType.RegisterTypes:
            foreach (MType type in m.moduleList)
            {
                modules.Add(type);
            }
            break;
        }
        messageDisplay.text = "Type: " + m.type + ", Subtype: " + m.sub.ToString() + ", Player: " + m.player + ", Other: " + m.other;
    }
Esempio n. 2
0
    // Handles new connection by inserting connectionId into list to be referenced for messaging.
    void onConnect(int hostId, int connectionId, int channelId, NetworkError error)
    {
        Debug.Log("Incoming connection event received: " + connectionId);

        try {
            userList.Add(connectionId, new HashSet <MType>());
        } catch (ArgumentException) {
            Debug.Log("Tried to add duplicate connectionId to userList!");
        }

        List <MType> list = new List <MType>();

        registerUser(connectionId, MType.Init);
        switch (connectionId)
        {
        case 1:
            registerUser(connectionId, MType.Pilot);
            list.Add(MType.Pilot);
            break;

        case 2:
            registerUser(connectionId, MType.Nav);
            list.Add(MType.Nav);
            break;

        default:
            break;
        }

        //send init message with module stuff
        SCInit init = new SCInit(SCInit.SubType.Init, connectionId, null, null);            // send initialization message with client's connectionId - used for (weak) authentication

        SendSocketMessage(init, connectionId);
        //SCInit init2 = new SCInit(SCInit.SubType.RegisterTypes, connectionId, list, null);
        SendSocketMessage(new SCInit(SCInit.SubType.RegisterTypes, connectionId, list, null), connectionId);
    }