mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-29 06:54:22 +01:00
Added network server messages (well, it's broken right now but anyway)
This commit is contained in:
parent
d24063b1a6
commit
e41dcc3c2b
@ -196,7 +196,12 @@ void C64::network_vblank()
|
||||
if (this->network_connection_type == CLIENT)
|
||||
this->TheDisplay->Update(remote->GetScreen());
|
||||
}
|
||||
if (this->network_connection_type == CONNECT)
|
||||
const char *msg = TheDisplay->GetTextMessage();
|
||||
if (msg)
|
||||
remote->EncodeTextMessage(msg, TheDisplay->text_message_broadcast);
|
||||
free((void *)msg);
|
||||
|
||||
if (this->network_connection_type == CONNECT)
|
||||
return;
|
||||
|
||||
/* Encode and send updates to the other side (what is determined by
|
||||
@ -212,11 +217,6 @@ void C64::network_vblank()
|
||||
}
|
||||
}
|
||||
|
||||
const char *msg = TheDisplay->GetTextMessage();
|
||||
if (msg)
|
||||
remote->EncodeTextMessage(msg);
|
||||
free((void *)msg);
|
||||
|
||||
remote->EncodeJoystickUpdate(*js);
|
||||
|
||||
if (remote->SendPeerUpdate() == false)
|
||||
|
@ -648,10 +648,11 @@ private:
|
||||
const char **out;
|
||||
};
|
||||
|
||||
void C64Display::TypeNetworkMessage()
|
||||
void C64Display::TypeNetworkMessage(bool broadcast)
|
||||
{
|
||||
TypeNetworkMessageListener *nl = new TypeNetworkMessageListener(&this->text_message_send);
|
||||
|
||||
this->text_message_broadcast = broadcast;
|
||||
Gui::gui->status_bar->queueMessage("Type message to send to peer");
|
||||
VirtualKeyboard::kbd->registerListener(nl);
|
||||
VirtualKeyboard::kbd->activate();
|
||||
|
@ -104,13 +104,15 @@ public:
|
||||
void InitColors(uint8 *colors);
|
||||
void NewPrefs(Prefs *prefs);
|
||||
|
||||
void TypeNetworkMessage();
|
||||
void TypeNetworkMessage(bool broadcast = false);
|
||||
|
||||
C64 *TheC64;
|
||||
|
||||
bool quit_requested;
|
||||
|
||||
|
||||
/* FIXME! Should not be public */
|
||||
bool text_message_broadcast;
|
||||
private:
|
||||
int led_state[4];
|
||||
int old_led_state[4];
|
||||
|
@ -382,7 +382,18 @@ void Network::EncodeTextMessage(const char *str, bool broadcast)
|
||||
memset(p, 0, len);
|
||||
snprintf(p, len - 1, "%s: %s", ThePrefs.NetworkName, str);
|
||||
|
||||
this->AddNetworkUpdate(dst);
|
||||
if (broadcast)
|
||||
{
|
||||
uint8_t *p_dst = (uint8_t *)dst;
|
||||
NetworkUpdate *stop = InitNetworkUpdate((NetworkUpdate*)(p_dst + dst->size),
|
||||
STOP, sizeof(NetworkUpdate));
|
||||
|
||||
this->MarshalData(dst);
|
||||
this->MarshalData(stop);
|
||||
this->SendUpdateDirect(&this->server_addr, dst);
|
||||
}
|
||||
else
|
||||
this->AddNetworkUpdate(dst);
|
||||
}
|
||||
|
||||
|
||||
@ -571,6 +582,34 @@ bool Network::ReceiveUpdate(NetworkUpdate *dst, size_t total_sz,
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Network::SendUpdateDirect(struct sockaddr_in *addr, NetworkUpdate *src)
|
||||
{
|
||||
uint8_t *p = (uint8_t *)src;
|
||||
size_t sz;
|
||||
|
||||
sz = src->size + sizeof(NetworkUpdate); /* stop */
|
||||
if (sz <= 0)
|
||||
return false;
|
||||
|
||||
size_t cur_sz = 0;
|
||||
do
|
||||
{
|
||||
size_t size_to_send = this->FillNetworkBuffer((NetworkUpdate*)p);
|
||||
ssize_t v;
|
||||
|
||||
v = this->SendTo((void*)p, this->sock,
|
||||
size_to_send, addr);
|
||||
if (v <= 0 || (size_t)v != size_to_send)
|
||||
return false;
|
||||
cur_sz += size_to_send;
|
||||
p += size_to_send;
|
||||
} while (cur_sz < sz);
|
||||
this->traffic += cur_sz;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Network::SendUpdate(struct sockaddr_in *addr)
|
||||
{
|
||||
NetworkUpdate *src = this->ud;
|
||||
|
@ -229,6 +229,8 @@ public:
|
||||
|
||||
void CloseSocket();
|
||||
|
||||
bool SendUpdateDirect(struct sockaddr_in *addr, NetworkUpdate *what);
|
||||
|
||||
bool SendUpdate(struct sockaddr_in *addr);
|
||||
|
||||
bool SendPeerUpdate()
|
||||
|
@ -84,7 +84,10 @@ public:
|
||||
if (TheC64->network_connection_type == NONE)
|
||||
Gui::gui->pushDialogueBox(new DialogueBox(network_need_connection));
|
||||
else
|
||||
printf("Send message NYI\n"); // FIXME! Send message
|
||||
{
|
||||
Gui::gui->exitMenu();
|
||||
TheC64->TheDisplay->TypeNetworkMessage(true);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (TheC64->network_connection_type != MASTER &&
|
||||
|
Loading…
Reference in New Issue
Block a user