mirror of
https://github.com/afska/gba-link-connection.git
synced 2026-04-25 08:07:59 -05:00
Adding LinkWireless::closeServer()
This commit is contained in:
parent
b2b1926d4a
commit
d645d47ba8
|
|
@ -239,6 +239,7 @@ You can also change these compile-time constants:
|
|||
| `activate()` | **bool** | Activates the library. When an adapter is connected, it changes the state to `AUTHENTICATED`. It can also be used to disconnect or reset the adapter. |
|
||||
| `deactivate()` | **bool** | Puts the adapter into a low consumption mode and then deactivates the library. It returns a boolean indicating whether the transition to low consumption mode was successful. You can disable the transition and deactivate directly by setting `turnOff` to `true`. |
|
||||
| `serve([gameName], [userName], [gameId])` | **bool** | Starts broadcasting a server and changes the state to `SERVING`. You can, optionally, provide a `gameName` (max `14` characters), a `userName` (max `8` characters), and a `gameId` _(0 ~ 0x7FFF)_ that games will be able to read. The strings must be null-terminated character arrays. If the adapter is already serving, this method only updates the broadcast data. Updating broadcast data while serving can fail if the adapter is busy. In that case, this will return `false` and `getLastError()` will be `BUSY_TRY_AGAIN`. |
|
||||
| `closeServer()` | **bool** | Closes the server while keeping the session active, to prevent new users from joining the room. Closing the server can fail if the adapter is busy. In that case, this will return `false` and `getLastError()` will be `BUSY_TRY_AGAIN`. |
|
||||
| `getServers(servers, [onWait])` | **bool** | Fills the `servers` array with all the currently broadcasting servers. This action takes 1 second to complete, but you can optionally provide an `onWait()` function which will be invoked each time VBlank starts. |
|
||||
| `getServersAsyncStart()` | **bool** | Starts looking for broadcasting servers and changes the state to `SEARCHING`. After this, call `getServersAsyncEnd(...)` 1 second later. |
|
||||
| `getServersAsyncEnd(servers)` | **bool** | Fills the `servers` array with all the currently broadcasting servers. Changes the state to `AUTHENTICATED` again. |
|
||||
|
|
|
|||
|
|
@ -13,15 +13,15 @@
|
|||
|
||||
The Mobile Adapter GB was an accessory designed to allow the Game Boy Color, and later the Game Boy Advance, to connect online via cellular networks in Japan. Released on January 27, 2001, it supported a limited number of games before service was shutdown on December 14, 2002. Many of the compatible games supported features such on mail clients, downloadable bonus content, player-versus-player modes, and even online tournaments. It represented Nintendo's first official attempt at online gaming for its handhelds.
|
||||
|
||||
* The Mobile Adapter is a small device that essentially allows a Japanese phone to connect to the Game Boy's link port
|
||||
* Model number is CGB-005
|
||||
* Officially released with 3 different versions of the Mobile Adapter. Each featured distinct colors to work with different type of phones
|
||||
* Each Mobile Adapter came packaged with a cartridge called the Mobile Trainer to help configure and setup the device
|
||||
* Servers were formally hosted at gameboy.datacenter.ne.jp
|
||||
- The Mobile Adapter is a small device that essentially allows a Japanese phone to connect to the Game Boy's link port
|
||||
- Model number is CGB-005
|
||||
- Officially released with 3 different versions of the Mobile Adapter. Each featured distinct colors to work with different type of phones
|
||||
- Each Mobile Adapter came packaged with a cartridge called the Mobile Trainer to help configure and setup the device
|
||||
- Servers were formally hosted at gameboy.datacenter.ne.jp
|
||||
|
||||
Below, the Mobile Adapter variants are explained in further detail:
|
||||
|
||||
Blue -> Used to connect PDC phones.
|
||||
Blue -> Used to connect PDC phones.
|
||||
Yellow -> Used to connect cdmaOne phones.
|
||||
Red -> Used to connect DDI phones.
|
||||
Green -> Would have been used to connect PHS phones, but this version was never released.
|
||||
|
|
@ -32,31 +32,31 @@ There are currently 22 known games that are compatible with the Mobile Adapter:
|
|||
|
||||
Game Boy Color : 6 Total
|
||||
|
||||
* Game Boy Wars 3
|
||||
* Hello Kitty: Happy House
|
||||
* Mobile Golf
|
||||
* Mobile Trainer
|
||||
* Net de Get Minigames @ 100
|
||||
* Pocket Monsters Crystal Version
|
||||
- Game Boy Wars 3
|
||||
- Hello Kitty: Happy House
|
||||
- Mobile Golf
|
||||
- Mobile Trainer
|
||||
- Net de Get Minigames @ 100
|
||||
- Pocket Monsters Crystal Version
|
||||
|
||||
Game Boy Advance : 16 Total
|
||||
|
||||
* All-Japan GT Championship
|
||||
* Daisenryaku For Game Boy Advance
|
||||
* Doraemon: Midori no Wakusei Doki Doki Daikyuushuutsu!
|
||||
* Exciting Bass
|
||||
* EX Monopoly
|
||||
* JGTO Licensed: Golfmaster Mobile
|
||||
* Kinniku Banzuke ~Kongou-kun no Daibouken!~
|
||||
* Mail de Cute
|
||||
* Mario Kart Advance
|
||||
* Mobile Pro Baseball: Control Baton
|
||||
* Monster Guardians
|
||||
* Morita Shougi Advance
|
||||
* Napoleon
|
||||
* Play Novel: Silent Hill
|
||||
* Starcom: Star Communicator
|
||||
* Zero-Tours
|
||||
- All-Japan GT Championship
|
||||
- Daisenryaku For Game Boy Advance
|
||||
- Doraemon: Midori no Wakusei Doki Doki Daikyuushuutsu!
|
||||
- Exciting Bass
|
||||
- EX Monopoly
|
||||
- JGTO Licensed: Golfmaster Mobile
|
||||
- Kinniku Banzuke ~Kongou-kun no Daibouken!~
|
||||
- Mail de Cute
|
||||
- Mario Kart Advance
|
||||
- Mobile Pro Baseball: Control Baton
|
||||
- Monster Guardians
|
||||
- Morita Shougi Advance
|
||||
- Napoleon
|
||||
- Play Novel: Silent Hill
|
||||
- Starcom: Star Communicator
|
||||
- Zero-Tours
|
||||
|
||||
Two games were planned but later cancelled: **beatmaniaGB Net Jam** for the GBC and **Horse Racing Creating Derby** for the GBA.
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ On the GBC, the Mobile Adapter operates using the fastest available setting (64K
|
|||
|
||||
```
|
||||
-------------------------------------------------
|
||||
Section | Length
|
||||
Section | Length
|
||||
-------------------------------------------------
|
||||
Magic Bytes : 0x99 0x66 | 2 bytes
|
||||
Packet Header | 4 bytes
|
||||
|
|
@ -96,7 +96,7 @@ Bytes 0-254 | Arbitrary data
|
|||
|
||||
|
||||
-------------------------------------------------
|
||||
Packet Checksum
|
||||
Packet Checksum
|
||||
-------------------------------------------------
|
||||
Byte 1 | High byte of 16-bit sum
|
||||
Byte 2 | Low byte of 16-bit sum
|
||||
|
|
@ -144,14 +144,15 @@ Even though the protocol effectively enables 2-way communication between the Gam
|
|||
|
||||
It is up to the game software itself to handle secondary protocols (such as HTTP, POP3, or SMTP) which involve one side specifically acting as the sender or receiver. For example, after opening a TCP connection to an HTTP server and issuing the 0x15 command (Data Transfer), the software will determine whether the Game Boy is acting as a sender (making an HTTP request) or a receiver (receiving an HTTP response). Generally, this goes back and forth. The Game Boy sends information via its Packet Data, while the Mobile Adapter responds with 0xD2 "wait" bytes until the Game Boy finishes its TCP transfer. When the Game Boy's TCP transfer is done, the adapter sends any information from the server in its Packet Data while the Game Boy responds with 0x4B "wait" bytes. The chart below illustrates this concept and details what bytes are transferred by each side depending on their current role:
|
||||
|
||||
Device | Role | Magic Bytes | Packet Header | Packet Checksum | Packet Data | Acknowledgement Signal
|
||||
--- | --- | --- | --- | --- | --- | ---
|
||||
Game Boy | Sender | 0x96 0x66 | Arbitrary | Arbitrary | Arbitrary | Device ID OR 0x80 + 0x00
|
||||
Mobile Adapter | Receiver | 0xD2 0xD2 | 0xD2 0xD2 ... | 0xD2 0xD2 ... ... ... | 0xD2 0xD2 ... | Device ID OR 0x80 + Command ID XOR 0x80
|
||||
--- | --- | --- | --- | --- | --- | ---
|
||||
Game Boy | Receiver | 0x4B 0x4B | 0x4B 0x4B ... | 0x4B 0x4B ... ... ... | 0x4B 0x4B ... | Device ID OR 0x80 + Command ID XOR 0x80
|
||||
Mobile Adapter | Sender | 0x96 0x66 | Arbitrary | Arbitrary | Arbitrary | Device ID OR 0x80 + 0x00
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
| Device | Role | Magic Bytes | Packet Header | Packet Checksum | Packet Data | Acknowledgement Signal |
|
||||
| -------------- | -------- | ----------- | ------------- | --------------------- | ------------- | --------------------------------------- |
|
||||
| Game Boy | Sender | 0x96 0x66 | Arbitrary | Arbitrary | Arbitrary | Device ID OR 0x80 + 0x00 |
|
||||
| Mobile Adapter | Receiver | 0xD2 0xD2 | 0xD2 0xD2 ... | 0xD2 0xD2 ... ... ... | 0xD2 0xD2 ... | Device ID OR 0x80 + Command ID XOR 0x80 |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| Game Boy | Receiver | 0x4B 0x4B | 0x4B 0x4B ... | 0x4B 0x4B ... ... ... | 0x4B 0x4B ... | Device ID OR 0x80 + Command ID XOR 0x80 |
|
||||
| Mobile Adapter | Sender | 0x96 0x66 | Arbitrary | Arbitrary | Arbitrary | Device ID OR 0x80 + 0x00 |
|
||||
|
||||
---
|
||||
|
||||
When beginning communications with the Mobile Adapter, the Game Boy typically assumes the role of sender first.
|
||||
|
||||
|
|
@ -343,7 +344,7 @@ Data Sent: Domain Name
|
|||
|
||||
Data Received: 4 bytes for IP Address
|
||||
|
||||
Looks up the IP address for a domain name, using the DNS server addresses sent in Command 0x21. This command also accepts an ASCII IPv4 address (as parsed by the inet\_addr(3) function of POSIX), converting it into a 4-byte IPv4 address instead of querying the DNS server. The domain name is in ASCII and may contain zeroes, which truncate the name.
|
||||
Looks up the IP address for a domain name, using the DNS server addresses sent in Command 0x21. This command also accepts an ASCII IPv4 address (as parsed by the inet_addr(3) function of POSIX), converting it into a 4-byte IPv4 address instead of querying the DNS server. The domain name is in ASCII and may contain zeroes, which truncate the name.
|
||||
|
||||
**Command 0x3F - Firmware Version**
|
||||
|
||||
|
|
|
|||
|
|
@ -363,6 +363,17 @@ void messageLoop() {
|
|||
waitFor(KEY_DOWN);
|
||||
}
|
||||
}
|
||||
|
||||
// In the profiler ROM, pressing START+UP will close the server
|
||||
if ((keys & KEY_START) &&
|
||||
linkWireless->getState() == LinkWireless::State::SERVING) {
|
||||
linkWireless->closeServer();
|
||||
if (linkWireless->getLastError() ==
|
||||
LinkWireless::Error::BUSY_TRY_AGAIN) {
|
||||
log("Busy!");
|
||||
waitFor(KEY_DOWN);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
altView = !altView;
|
||||
|
|
|
|||
|
|
@ -208,6 +208,7 @@ class LinkWireless {
|
|||
static constexpr int COMMAND_BROADCAST = 0x16;
|
||||
static constexpr int COMMAND_START_HOST = 0x19;
|
||||
static constexpr int COMMAND_ACCEPT_CONNECTIONS = 0x1a;
|
||||
static constexpr int COMMAND_END_HOST = 0x1b;
|
||||
static constexpr int COMMAND_BROADCAST_READ_START = 0x1c;
|
||||
static constexpr int COMMAND_BROADCAST_READ_POLL = 0x1d;
|
||||
static constexpr int COMMAND_BROADCAST_READ_END = 0x1e;
|
||||
|
|
@ -438,6 +439,40 @@ class LinkWireless {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Closes the server while keeping the session active, to prevent new
|
||||
* users from joining the room.
|
||||
* \warning Closing the server can fail if the adapter is busy. In that case,
|
||||
* this will return `false` and `getLastError()` will be `BUSY_TRY_AGAIN`.
|
||||
*/
|
||||
bool closeServer() {
|
||||
LINK_WIRELESS_RESET_IF_NEEDED
|
||||
if (state != SERVING) {
|
||||
lastError = WRONG_STATE;
|
||||
return false;
|
||||
}
|
||||
|
||||
isSendingSyncCommand = true;
|
||||
if (asyncCommand.isActive) {
|
||||
lastError = BUSY_TRY_AGAIN;
|
||||
isSendingSyncCommand = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
sessionState.serverClosed = true;
|
||||
sessionState.acceptCalled = true;
|
||||
|
||||
bool success = sendCommand(COMMAND_END_HOST, false).success;
|
||||
|
||||
if (!success) {
|
||||
reset();
|
||||
lastError = COMMAND_FAILED;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fills the `servers` array with all the currently broadcasting
|
||||
* servers.
|
||||
|
|
@ -861,7 +896,8 @@ class LinkWireless {
|
|||
#endif
|
||||
|
||||
sessionState.recvFlag = false;
|
||||
sessionState.acceptCalled = false;
|
||||
if (!sessionState.serverClosed)
|
||||
sessionState.acceptCalled = false;
|
||||
sessionState.pingSent = false;
|
||||
|
||||
#ifdef PROFILING_ENABLED
|
||||
|
|
@ -978,6 +1014,7 @@ class LinkWireless {
|
|||
bool msgFlags[LINK_WIRELESS_MAX_PLAYERS]; // (~= LinkCable::msgFlags)
|
||||
|
||||
bool acceptCalled = false;
|
||||
bool serverClosed = false;
|
||||
bool pingSent = false;
|
||||
#ifdef LINK_WIRELESS_USE_SEND_RECEIVE_LATCH
|
||||
bool sendReceiveLatch = false; // true = send ; false = receive
|
||||
|
|
@ -1567,6 +1604,7 @@ class LinkWireless {
|
|||
this->sessionState.recvFlag = false;
|
||||
this->sessionState.recvTimeout = 0;
|
||||
this->sessionState.acceptCalled = false;
|
||||
this->sessionState.serverClosed = false;
|
||||
this->sessionState.pingSent = false;
|
||||
#ifdef LINK_WIRELESS_USE_SEND_RECEIVE_LATCH
|
||||
this->sessionState.sendReceiveLatch = false;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ bool C_LinkWireless_serve(C_LinkWirelessHandle handle,
|
|||
return static_cast<LinkWireless*>(handle)->serve(gameName, userName, gameId);
|
||||
}
|
||||
|
||||
bool C_LinkWireless_closeServer(C_LinkWirelessHandle handle) {
|
||||
return static_cast<LinkWireless*>(handle)->closeServer();
|
||||
}
|
||||
|
||||
bool C_LinkWireless_getServers(C_LinkWirelessHandle handle,
|
||||
C_LinkWireless_Server servers[]) {
|
||||
LinkWireless::Server cppServers[C_LINK_WIRELESS_MAX_SERVERS];
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ bool C_LinkWireless_serve(C_LinkWirelessHandle handle,
|
|||
const char* gameName,
|
||||
const char* userName,
|
||||
u16 gameId);
|
||||
bool C_LinkWireless_closeServer(C_LinkWirelessHandle handle);
|
||||
|
||||
bool C_LinkWireless_getServers(C_LinkWirelessHandle handle,
|
||||
C_LinkWireless_Server servers[]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user