Added network server messages (well, it's broken right now but anyway)

This commit is contained in:
simon.kagstrom 2010-02-21 16:33:25 +00:00
parent d24063b1a6
commit e41dcc3c2b
6 changed files with 57 additions and 10 deletions

View File

@ -196,7 +196,12 @@ void C64::network_vblank()
if (this->network_connection_type == CLIENT) if (this->network_connection_type == CLIENT)
this->TheDisplay->Update(remote->GetScreen()); 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; return;
/* Encode and send updates to the other side (what is determined by /* 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); remote->EncodeJoystickUpdate(*js);
if (remote->SendPeerUpdate() == false) if (remote->SendPeerUpdate() == false)

View File

@ -648,10 +648,11 @@ private:
const char **out; const char **out;
}; };
void C64Display::TypeNetworkMessage() void C64Display::TypeNetworkMessage(bool broadcast)
{ {
TypeNetworkMessageListener *nl = new TypeNetworkMessageListener(&this->text_message_send); TypeNetworkMessageListener *nl = new TypeNetworkMessageListener(&this->text_message_send);
this->text_message_broadcast = broadcast;
Gui::gui->status_bar->queueMessage("Type message to send to peer"); Gui::gui->status_bar->queueMessage("Type message to send to peer");
VirtualKeyboard::kbd->registerListener(nl); VirtualKeyboard::kbd->registerListener(nl);
VirtualKeyboard::kbd->activate(); VirtualKeyboard::kbd->activate();

View File

@ -104,13 +104,15 @@ public:
void InitColors(uint8 *colors); void InitColors(uint8 *colors);
void NewPrefs(Prefs *prefs); void NewPrefs(Prefs *prefs);
void TypeNetworkMessage(); void TypeNetworkMessage(bool broadcast = false);
C64 *TheC64; C64 *TheC64;
bool quit_requested; bool quit_requested;
/* FIXME! Should not be public */
bool text_message_broadcast;
private: private:
int led_state[4]; int led_state[4];
int old_led_state[4]; int old_led_state[4];

View File

@ -382,7 +382,18 @@ void Network::EncodeTextMessage(const char *str, bool broadcast)
memset(p, 0, len); memset(p, 0, len);
snprintf(p, len - 1, "%s: %s", ThePrefs.NetworkName, str); 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; 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) bool Network::SendUpdate(struct sockaddr_in *addr)
{ {
NetworkUpdate *src = this->ud; NetworkUpdate *src = this->ud;

View File

@ -229,6 +229,8 @@ public:
void CloseSocket(); void CloseSocket();
bool SendUpdateDirect(struct sockaddr_in *addr, NetworkUpdate *what);
bool SendUpdate(struct sockaddr_in *addr); bool SendUpdate(struct sockaddr_in *addr);
bool SendPeerUpdate() bool SendPeerUpdate()

View File

@ -84,7 +84,10 @@ public:
if (TheC64->network_connection_type == NONE) if (TheC64->network_connection_type == NONE)
Gui::gui->pushDialogueBox(new DialogueBox(network_need_connection)); Gui::gui->pushDialogueBox(new DialogueBox(network_need_connection));
else else
printf("Send message NYI\n"); // FIXME! Send message {
Gui::gui->exitMenu();
TheC64->TheDisplay->TypeNetworkMessage(true);
}
break; break;
case 7: case 7:
if (TheC64->network_connection_type != MASTER && if (TheC64->network_connection_type != MASTER &&