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,6 +196,11 @@ void C64::network_vblank()
if (this->network_connection_type == CLIENT)
this->TheDisplay->Update(remote->GetScreen());
}
const char *msg = TheDisplay->GetTextMessage();
if (msg)
remote->EncodeTextMessage(msg, TheDisplay->text_message_broadcast);
free((void *)msg);
if (this->network_connection_type == CONNECT)
return;
@ -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)

View File

@ -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();

View File

@ -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];

View File

@ -382,6 +382,17 @@ void Network::EncodeTextMessage(const char *str, bool broadcast)
memset(p, 0, len);
snprintf(p, len - 1, "%s: %s", ThePrefs.NetworkName, str);
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;

View File

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

View File

@ -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 &&