Example #1
0
void MeshBase::SendPeerDiscovery()
{
	last_broadcast_time = millis();
	MeshBase::PeerDiscoveryMessage msg;
	msg.version = 1;
	msg.address = address;
	msg.num_peers = peers.length;
	SendBroadcastMessage(PEER_DISCOVERY, &msg, sizeof(MeshBase::PeerDiscoveryMessage));
}
Example #2
0
int main(void) {
	users_t users[MAX_USERS];
	char buf[100];
	int done = 0;

//	BusyWork();

	// set a global pointer for easier function access
	USERS = users;

	// init some vars
	ADMIN_ACCESS = 0;
	CURRENT_USER = -1;
	NUM_USERS = 0;
	zero((char *)USERS, sizeof(users_t)*MAX_USERS);

	while (!done) {
		if (ADMIN_ACCESS) {
			zero(buf, 100);
			PrintAdminMenu();
			if (read_until(buf, '\n', 100) == -1) {
				_terminate(-1);
			}
			if (strlen(buf) > 1) {
				print("[-] Invalid choice\n");
				continue;
			}
			switch (buf[0]) {
				case '1':
					SendBroadcastMessage();
					break;

				case '2':
					ADMIN_ACCESS = 0;
					break;

				case '3':
					print("Exiting...\n");
					done = 1;
					break;

				default:
					continue;
			}
		} else if (CURRENT_USER == -1) {
			zero(buf, 100);
			PrintLoggedOutMenu();
			if (read_until(buf, '\n', 100) == -1) {
				_terminate(-1);
			}
			if (strlen(buf) > 1) {
				print("[-] Invalid choice\n");
				continue;
			}
			switch (buf[0]) {
				case '1':
					CreateUser();
					break;
				case '2':
					Login();
					break;
				case '3':
					print("Exiting...\n");
					_terminate(0);
					break;
				default:
					print("[-] Invalid choice\n");
					continue;
			}
		} else {
			zero(buf, 100);
			PrintNewMessages();
			PrintLoggedInMenu();
			if (read_until(buf, '\n', 100) == -1) {
				_terminate(-1);
			}
			if (strlen(buf) > 1) {
				print("[-] Invalid choice\n");
				continue;
			}
			switch (buf[0]) {
				case '1':
					SendMessage();
					break;
				case '2':
					ReadMessage();
					break;
				case '3':
					ListMessages();
					break;
				case '4':
					DeleteMessage();
					break;
				case '5':
					CURRENT_USER = -1;
					print("Logging out...\n");
					break;
				case '6':
					print("Exiting...\n");
					_terminate(0);
					break;
				case 'a':
					AdminLogin();
					break;
				default:
					print("[-] Invalid choice\n");
					continue;
			}
		}
	}

	return(0);
}