Exemplo n.º 1
0
 public void OnDestroy()
 {
     if (client != null)
     {
         client.Close();
         client = null;
     }
 }
Exemplo n.º 2
0
    void relay_start_callback(object req, ApiClient api_client)
    {
        if (null != req)
        {
            RelayStart relay_start = (RelayStart)req;

            relay_info = relay_start.response;

            string[] address = relay_info.server_address.Split(':');

            if (client != null)
            {
                if (true == client.IsConnected())
                {
                    log("already connected server. server[" + address[0] + ":" + address[1] + "]");
                    return;
                }
            }
            else
            {
                client = new wise.net.Client();
            }

            if (false == client.Connect(address[0], int.Parse(address[1])))
            {
                log("cannot connect server. server[" + address[0] + ":" + address[1] + "]");
                return;
            }

            log("connect server. server[" + address[0] + ":" + address[1] + "]");

            foreach (var member in relay_info.members)
            {
                if (member.id == user_index.ToString())
                {
                    FlatBuffers.FlatBufferBuilder builder = new FlatBuffers.FlatBufferBuilder(1);
                    var offset = PACKET.ENTER.CreateENTER(builder, builder.CreateString(login_info.UserID), builder.CreateString(member.hash), user_index);
                    builder.Finish(offset.Value);

                    if (false == client.Send((int)PACKET_C2S.ENTER, builder.SizedByteArray(), uint.Parse(relay_info.roomnum.ToString())))
                    {
                        log("can't enter.");
                    }
                    return;
                }
            }

            log("not find my information from relay/start.");
        }
        else
        {
            log("failed relay_start.");
        }
    }