mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-09-14 15:16:40 +00:00
Merge pull request #2688 from Che177/feature/room-server-system-posts
room_server: add room.post command for server-originated posts
This commit is contained in:
@@ -39,18 +39,35 @@ struct ServerStats {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void MyMesh::addPost(ClientInfo *client, const char *postData) {
|
void MyMesh::addPost(ClientInfo *client, const char *postData) {
|
||||||
// TODO: suggested postData format: <title>/<descrption>
|
storePost(client->id, postData);
|
||||||
posts[next_post_idx].author = client->id; // add to cyclic queue
|
}
|
||||||
StrHelper::strncpy(posts[next_post_idx].text, postData, MAX_POST_TEXT_LEN);
|
|
||||||
|
|
||||||
posts[next_post_idx].post_timestamp = getRTCClock()->getCurrentTimeUnique();
|
void MyMesh::addSystemPost(const char *postData) {
|
||||||
|
if (!postData || postData[0] == 0) return;
|
||||||
|
|
||||||
|
MESH_DEBUG_PRINTLN("room.post: addSystemPost: %s", postData);
|
||||||
|
|
||||||
|
storePost(self_id, postData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyMesh::storePost(const mesh::Identity &author, const char *postData) {
|
||||||
|
int idx = next_post_idx;
|
||||||
|
// TODO: suggested postData format: <title>/<descrption>
|
||||||
|
posts[idx].author = author; // add to cyclic queue
|
||||||
|
StrHelper::strncpy(posts[idx].text, postData, MAX_POST_TEXT_LEN);
|
||||||
|
|
||||||
|
posts[idx].post_timestamp = getRTCClock()->getCurrentTimeUnique();
|
||||||
|
MESH_DEBUG_PRINTLN("room.post: storePost idx=%d text=%s", idx, posts[idx].text);
|
||||||
|
MESH_DEBUG_PRINTLN("room.post: timestamp=%u", posts[idx].post_timestamp);
|
||||||
next_post_idx = (next_post_idx + 1) % MAX_UNSYNCED_POSTS;
|
next_post_idx = (next_post_idx + 1) % MAX_UNSYNCED_POSTS;
|
||||||
|
|
||||||
next_push = futureMillis(PUSH_NOTIFY_DELAY_MILLIS);
|
next_push = futureMillis(PUSH_NOTIFY_DELAY_MILLIS);
|
||||||
_num_posted++; // stats
|
_num_posted++; // stats
|
||||||
|
MESH_DEBUG_PRINTLN("room.post: next_post_idx=%d num_posted=%d push scheduled", next_post_idx, _num_posted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyMesh::pushPostToClient(ClientInfo *client, PostInfo &post) {
|
void MyMesh::pushPostToClient(ClientInfo *client, PostInfo &post) {
|
||||||
|
MESH_DEBUG_PRINTLN("room.post: pushPostToClient text=%s", post.text);
|
||||||
int len = 0;
|
int len = 0;
|
||||||
memcpy(&reply_data[len], &post.post_timestamp, 4);
|
memcpy(&reply_data[len], &post.post_timestamp, 4);
|
||||||
len += 4; // this is a PAST timestamp... but should be accepted by client
|
len += 4; // this is a PAST timestamp... but should be accepted by client
|
||||||
@@ -948,6 +965,15 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
|
|||||||
Serial.printf("\n");
|
Serial.printf("\n");
|
||||||
}
|
}
|
||||||
reply[0] = 0;
|
reply[0] = 0;
|
||||||
|
} else if (strncmp(command, "room.post", 9) == 0) {
|
||||||
|
char* msg = command + 9;
|
||||||
|
while (*msg == ' ') msg++;
|
||||||
|
if (*msg == 0) {
|
||||||
|
snprintf(reply, MAX_POST_TEXT_LEN, "ERR empty message");
|
||||||
|
} else {
|
||||||
|
addSystemPost(msg);
|
||||||
|
snprintf(reply, MAX_POST_TEXT_LEN, "OK");
|
||||||
|
}
|
||||||
} else{
|
} else{
|
||||||
_cli.handleCommand(sender_timestamp, command, reply); // common CLI commands
|
_cli.handleCommand(sender_timestamp, command, reply); // common CLI commands
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
|||||||
int matching_peer_indexes[MAX_CLIENTS];
|
int matching_peer_indexes[MAX_CLIENTS];
|
||||||
|
|
||||||
void addPost(ClientInfo* client, const char* postData);
|
void addPost(ClientInfo* client, const char* postData);
|
||||||
|
void storePost(const mesh::Identity& author, const char* postData);
|
||||||
void pushPostToClient(ClientInfo* client, PostInfo& post);
|
void pushPostToClient(ClientInfo* client, PostInfo& post);
|
||||||
uint8_t getUnsyncedCount(ClientInfo* client);
|
uint8_t getUnsyncedCount(ClientInfo* client);
|
||||||
bool processAck(const uint8_t *data);
|
bool processAck(const uint8_t *data);
|
||||||
@@ -176,6 +177,7 @@ public:
|
|||||||
MyMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables);
|
MyMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables);
|
||||||
|
|
||||||
void begin(FILESYSTEM* fs);
|
void begin(FILESYSTEM* fs);
|
||||||
|
void addSystemPost(const char* postData);
|
||||||
|
|
||||||
const char* getFirmwareVer() override { return FIRMWARE_VERSION; }
|
const char* getFirmwareVer() override { return FIRMWARE_VERSION; }
|
||||||
const char* getBuildDate() override { return FIRMWARE_BUILD_DATE; }
|
const char* getBuildDate() override { return FIRMWARE_BUILD_DATE; }
|
||||||
|
|||||||
Reference in New Issue
Block a user