static void ReceivedEvent(Session session, byte[] bytes) { switch (ProtoMaker.GetProtoType(bytes)) { case ProtoType.Admin: var admin = ProtoMaker.Unpack <Client2Server.Admin>(bytes); Console.WriteLine(admin.Message); break; case ProtoType.UserAuth: var auth = ProtoMaker.Unpack <Client2Server.UserAuth>(bytes); Console.WriteLine("Username : {0}, Password : {1}", auth.Username, auth.Password); // TODO : DBから認証情報をチェック session.userInfo.Auth(); session.userInfo.Username = auth.Username; session.Send(ProtoMaker.Pack(new Server2Client.UserAuth { Username = session.userInfo.Username, })); break; case ProtoType.UserInfo: var info = new Server2Client.UserInfo(); info.numUser = sessions.Count; info.Username = new string[sessions.Count]; for (var i = 0; i < sessions.Count; ++i) { info.Username[i] = sessions[i].userInfo.Username; } session.Send(ProtoMaker.Pack(info)); break; case ProtoType.UserChat: var c2sChat = ProtoMaker.Unpack <Client2Server.UserChat>(bytes); var s2CChat = ProtoMaker.Pack(new Server2Client.UserChat { Username = session.userInfo.Username, Message = c2sChat.Message }); // 全員配信 for (var i = 0; i < sessions.Count; ++i) { sessions[i].Send(s2CChat); } break; case ProtoType.CmdMove: // 全員配信 var s2CMove = ProtoMaker.Pack(ProtoType.UserMove); for (var i = 0; i < sessions.Count; ++i) { sessions[i].Send(s2CMove); } break; } }
void Received(byte[] bytes) { switch (ProtoMaker.GetProtoType(bytes)) { case ProtoType.Admin: var admin = ProtoMaker.Unpack <Server2Client.Admin>(bytes); LoggerService.Locator.Log(admin.Message); break; case ProtoType.UserAuth: var auth = ProtoMaker.Unpack <Server2Client.UserAuth>(bytes); LoggerService.Locator.Log("Username : {0}", auth.Username); SceneManager.LoadScene("Room"); // 入室 break; } }
void Received(byte[] bytes) { switch (ProtoMaker.GetProtoType(bytes)) { case ProtoType.UserInfo: var info = ProtoMaker.Unpack <Server2Client.UserInfo>(bytes); usernames.text = String.Join("\n", info.Username); break; case ProtoType.UserChat: var chat = ProtoMaker.Unpack <Server2Client.UserChat>(bytes); AddMessage(String.Format("{0} : {1}", chat.Username, chat.Message)); break; case ProtoType.UserMove: // 誰か入室した // ユーザ一覧取得:手軽なのでこのサンプルは一覧すべて取得する SocketService.Locator.Send(ProtoMaker.Pack(ProtoType.UserInfo)); break; } }