Skip to content

Commit 9a4c87b

Browse files
committed
add server ip cache reset api for future work on config tool/installer, fallback to default profile if hotspot.txt is somehow missing
1 parent 4f196ce commit 9a4c87b

3 files changed

Lines changed: 10 additions & 45 deletions

File tree

pspnet_adhoc/exports.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ PSP_EXPORT_END
3737

3838
PSP_EXPORT_START(sceNetAdhocInternal, 0x0011, 0x0001)
3939
PSP_EXPORT_FUNC_NID(resolve_server_ip, 0x1)
40+
PSP_EXPORT_FUNC_NID(reset_server_ip_cache, 0x2)
4041
PSP_EXPORT_END
4142

4243

pspnet_adhoc/library/calls/pdp/create.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
static uint32_t server_ip = 0;
2121

22+
void reset_server_ip_cache(){
23+
server_ip = 0;
24+
}
25+
2226
uint32_t resolve_server_ip(){
2327
sceKernelWaitSema(_server_resolve_mutex, 1, 0);
2428

pspnet_adhocctl/library/calls/init.c

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ int _zero = 0;
7272
int _initNetwork(const SceNetAdhocctlAdhocId * adhoc_id);
7373
int _readHotspotConfig(void);
7474
int _findHotspotConfigId(char * ssid);
75-
const char * _readServerConfig(void);
7675
void _readChatKeyphrases(const SceNetAdhocctlAdhocId * adhoc_id);
7776
int _friendFinder(SceSize args, void * argp);
7877
void _addFriend(SceNetAdhocctlConnectPacketS2C * packet);
@@ -154,20 +153,7 @@ int proNetAdhocctlInit(int stacksize, int prio, const SceNetAdhocctlAdhocId * ad
154153
// Minimum Stacksize (just to fake SCE behaviour)
155154
if(stacksize >= 3072)
156155
{
157-
if (_readHotspotConfig() != 0)
158-
{
159-
printk("%s: failed reading hotspot config\n", __func__);
160-
return -1;
161-
}
162-
163-
// Get Server IP (String)
164-
const char * ip = _readServerConfig();
165-
166-
if (ip == NULL)
167-
{
168-
printk("%s: failed reading ip config\n", __func__);
169-
return -1;
170-
}
156+
_readHotspotConfig();
171157

172158
if (_initNetwork(adhoc_id) != 0)
173159
{
@@ -462,13 +448,16 @@ int _readHotspotConfig(void)
462448
if(_hotspot != -1) printk("Selected Hotspot: %s\n", line);
463449

464450
// No Hotspot found
465-
else printk("Couldn't find Hotspot: %s\n", line);
451+
else printk("warning: couldn't find Hotspot: %s, falling back to default hotspot id 0\n", line);
466452

467453
// Close Configuration File
468454
sceIoClose(fd);
469455

470456
// Return Success
471457
if(_hotspot >= 0) return 0;
458+
}else{
459+
printk("%s: warning: hotspot.txt missing, falling back to default hotspot id 0\n", __func__);
460+
_hotspot = 0;
472461
}
473462

474463
// Generic Error
@@ -506,35 +495,6 @@ int _findHotspotConfigId(char * ssid)
506495
return 0;
507496
}
508497

509-
/**
510-
* Read Server IP
511-
* @return IP != 0 on success or... 0
512-
*/
513-
const char * _readServerConfig(void)
514-
{
515-
// Line Buffer
516-
static char line[128];
517-
518-
// Open Configuration File
519-
int fd = sceIoOpen("ms0:/seplugins/server.txt", PSP_O_RDONLY, 0777);
520-
521-
// Opened Configuration File
522-
if(fd >= 0)
523-
{
524-
// Read Line
525-
_readLine(fd, line, sizeof(line));
526-
527-
// Close Configuration File
528-
sceIoClose(fd);
529-
530-
// Return IP (String)
531-
return line;
532-
}
533-
534-
// Generic Error
535-
return NULL;
536-
}
537-
538498
/**
539499
* Read Line from File
540500
* @param fd File Descriptor to read line from

0 commit comments

Comments
 (0)