[PD1] Cleaned up protocol,database and receiving multiple messageInfos
This commit is contained in:
parent
4c141bbc6e
commit
f3cf9cfc40
6 changed files with 347 additions and 231 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"PD1/internal/protocol"
|
||||
"PD1/internal/utils/cryptoUtils"
|
||||
"PD1/internal/utils/networking"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func clientHandler(connection networking.Connection[protocol.Packet], dataStore DataStore) {
|
||||
|
@ -24,33 +23,30 @@ F:
|
|||
for {
|
||||
pac, active := connection.Receive()
|
||||
if !active {
|
||||
break F
|
||||
break
|
||||
}
|
||||
switch pac.Flag {
|
||||
case protocol.ReqUserCertPkt:
|
||||
reqUserCert := protocol.UnmarshalRequestUserCertPacket(pac.Body)
|
||||
case protocol.FlagGetUserCert:
|
||||
reqUserCert := protocol.UnmarshalGetUserCert(pac.Body)
|
||||
userCertPacket := dataStore.GetUserCertificate(reqUserCert.UID)
|
||||
if active := connection.Send(userCertPacket); !active {
|
||||
break F
|
||||
}
|
||||
case protocol.ReqMsgsQueue:
|
||||
_ = protocol.UnmarshalRequestMsgsQueuePacket(pac.Body)
|
||||
messages := dataStore.GetUnreadMessagesInfoQueue(UID)
|
||||
fmt.Printf("Number of unread messages by user %v is %v\n",UID,len(messages))
|
||||
for _, message := range messages {
|
||||
if !connection.Send(message) {
|
||||
break
|
||||
}
|
||||
case protocol.FlagGetUnreadMsgsInfo:
|
||||
getUnreadMsgsInfo := protocol.UnmarshalGetUnreadMsgsInfo(pac.Body)
|
||||
messages := dataStore.GetUnreadMsgsInfo(UID,getUnreadMsgsInfo.Page,getUnreadMsgsInfo.PageSize)
|
||||
if !connection.Send(messages) {
|
||||
break F
|
||||
}
|
||||
case protocol.ReqMsgPkt:
|
||||
reqMsg := protocol.UnmarshalRequestMsgPacket(pac.Body)
|
||||
case protocol.FlagGetMsg:
|
||||
reqMsg := protocol.UnmarshalGetMsg(pac.Body)
|
||||
message := dataStore.GetMessage(UID, reqMsg.Num)
|
||||
if active := connection.Send(message); !active {
|
||||
break F
|
||||
}
|
||||
dataStore.MarkMessageInQueueAsRead(UID, reqMsg.Num)
|
||||
case protocol.SubmitMsgPkt:
|
||||
submitMsg := protocol.UnmarshalSubmitMessagePacket(pac.Body)
|
||||
dataStore.MarkMessageInQueueAsRead(UID, reqMsg.Num)
|
||||
case protocol.FlagSendMsg:
|
||||
submitMsg := protocol.UnmarshalSendMsg(pac.Body)
|
||||
if submitMsg.ToUID != UID && dataStore.userExists(submitMsg.ToUID) {
|
||||
dataStore.AddMessageToQueue(UID, submitMsg)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue