diff --git a/client/client.go b/client/client.go index a022c5b..e6e1e6f 100644 --- a/client/client.go +++ b/client/client.go @@ -114,6 +114,9 @@ func (cliCtx *Context) handleStartChatB(reqFrame cm.RFrame) (res cm.Response, er } func (cliCtx *Context) handleStartChatD(reqFrame cm.RFrame) (res cm.Response, err error) { + cliCtx.initiationsLock.Lock() + defer cliCtx.initiationsLock.Unlock() + startChatDReq, err := cm.RequestFromFrame[cm.StartChatDRequest](reqFrame) if err != nil { return nil, err @@ -123,6 +126,17 @@ func (cliCtx *Context) handleStartChatD(reqFrame cm.RFrame) (res cm.Response, er startChatDReq.Nickname, startChatDReq.PunchCode) logger.Warn("handleStartChatD not implemented yet") + idx := slices.IndexFunc(cliCtx.initiations, func(i *cm.Initiation) bool { + return i.AbBNick == startChatDReq.Nickname + }) + + if idx == -1 { + logger.Error("there is no initation related to chatstartd's nickname, ignoring") + return nil, nil + } + + cliCtx.initiations[idx].Stage = cm.InitiationStageD + return nil, nil } @@ -271,6 +285,9 @@ func sendStartChatA(ctx *Context, nick string) { } func sendStartChatC(ctx *Context, nick string) { + ctx.initiationsLock.Lock() + defer ctx.initiationsLock.Unlock() + idx := slices.IndexFunc(ctx.initiations, func(i *cm.Initiation) bool { return i.AbANick == nick }) @@ -287,6 +304,8 @@ func sendStartChatC(ctx *Context, nick string) { return } + ctx.initiations[idx].Stage = cm.InitiationStageC + logger.Debug("request sent, no wait for response") }