public async Task <string> getPacketResponse(string content, ClientData clientData) { string[] packet = content.Split('\t'); int packetSize = Convert.ToInt32(packet[0]); string packetType = packet[1]; int size = (content.Length - packet[0].Length - 1) - StringConstants.PacketEnding.Length; string returnMessage; if (Convert.ToInt32(packet[0]) != size) { returnMessage = buildDefault(packet); content = string.Format(StringConstants.GlobalPacketFormat, returnMessage.Length + 1, returnMessage, StringConstants.PacketEnding); return(content); } switch (packetType) { case StringConstants.RegisterPacketName: returnMessage = await buildRegister(packet); break; case StringConstants.LoginPacketName: returnMessage = await buildLogin(packet, clientData); break; case StringConstants.DisplayBlogsPacketName: returnMessage = await buildDisplayBlogs(packet); break; case StringConstants.DisplayBlogPacketName: returnMessage = await buildDisplayBlog(packet); break; case StringConstants.AddEntryPacketName: returnMessage = await buildAddEntry(packet, clientData); break; case StringConstants.DisplayEntryPacketName: returnMessage = await buildDisplayEntry(packet); break; case StringConstants.DeleteEntryPacketName: returnMessage = await buildDeleteEntry(packet, clientData); break; case StringConstants.ChangeBlogNamePacketName: returnMessage = await buildChangeBlogName(packet, clientData); break; case StringConstants.LogoutPacketName: returnMessage = buildLogout(packet, clientData); break; case StringConstants.ConnectionClosePacketName: returnMessage = buildExit(packet); break; case StringConstants.PingPacketName: returnMessage = "PONG"; break; default: returnMessage = buildDefault(packet); break; } //returnMessage = returnMessage + "\t"; //content = returnMessage.Length + "\t" + returnMessage + "/rn/rn/rn$$"; content = string.Format(StringConstants.GlobalPacketFormat, returnMessage.Length + 1, returnMessage, StringConstants.PacketEnding); return(content); }
private string buildLogout(string[] packet, ClientData clientData) { clientData.Id = -1; return(StringConstants.LogoutPacketName); }