少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <config.h>
#include <glib.h>
 
 
#include <mono/utils/networking.h>
 
#if defined(PLATFORM_UNITY) && defined(UNITY_USE_PLATFORM_STUBS)
 
#include "Socket-c-api.h"
 
static void
add_hostent(MonoAddressInfo *info, int flags, const char* name, gint family, char** aliases, void** addresses, int32_t addressSize)
{
    MonoAddressEntry *cur, *prev = info->entries;
    int idx = 0;
    int address_length = 0;
 
    if (!info->aliases)
        info->aliases = g_strdupv(aliases);
 
    while (addresses[idx]) {
        cur = g_new0(MonoAddressEntry, 1);
        if (prev)
            prev->next = cur;
        else
            info->entries = cur;
 
        if (flags & MONO_HINT_CANONICAL_NAME && name)
            cur->canonical_name = g_strdup(name);
 
        cur->family = family;
        cur->socktype = SOCK_STREAM;
        cur->protocol = 0; /* Zero means the default stream protocol */
        address_length = addressSize;
        cur->address_len = address_length;
        memcpy(&cur->address, addresses[idx], address_length);
 
        prev = cur;
        ++idx;
    }
}
 
static void free_null_terminated_array (void** array)
{
    if (array != NULL)
    {
        int i = 0;
        while (array[i] != NULL)
        {
            g_free(array[i]);
            i++;
        }
    }
    g_free(array);
}
 
int
mono_get_address_info(const char *hostname, int port, int flags, MonoAddressInfo **result)
{
    MonoAddressInfo *addr_info;
    addr_info = g_new0(MonoAddressInfo, 1);
 
    char* name;
    gint family;
    char** aliases;
    void** addresses;
    int32_t addressSize;
 
    if (UnityPalGetHostByName(hostname, &name, &family, &aliases, &addresses, &addressSize) == kWaitStatusSuccess)
        add_hostent(addr_info, flags, name, family, aliases, addresses, addressSize);
 
    g_free(name);
    free_null_terminated_array(aliases);
    free_null_terminated_array(addresses);
 
    if (!addr_info->entries) {
        *result = NULL;
        mono_free_address_info(addr_info);
        return 1;
    }
 
    *result = addr_info;
    return 0;
}
 
void *
mono_get_local_interfaces (int family, int *interface_count)
{
    g_assert(0 && "This function is not yet implemented for the Unity platform.");
    return NULL;
}
 
gboolean
mono_networking_addr_to_str (MonoAddress *address, char *buffer, socklen_t buflen)
{
    g_assert(0 && "This function is not yet implemented for the Unity platform.");
    return FALSE;
}
 
int
mono_networking_get_tcp_protocol (void)
{
    g_assert(0 && "This function is not yet implemented for the Unity platform.");
    return 0;
}
 
int
mono_networking_get_ip_protocol (void)
{
    g_assert(0 && "This function is not yet implemented for the Unity platform.");
    return 0;
}
 
int
mono_networking_get_ipv6_protocol (void)
{
    g_assert(0 && "This function is not yet implemented for the Unity platform.");
    return 0;
}
 
#endif /* PLATFORM_UNITY && UNITY_USE_PLATFORM_STUBS */