public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is CacheAgentMessageID) { if (data != null) { switch ((CacheAgentMessageID)msgID) { case CacheAgentMessageID.RequestCacheHash: { WaveMessage msgOut = new WaveMessage(); msgOut.AddBinary(CacheAgentFieldID.CacheHash, Server.CalculateHash()); // return cache's own CIID (if any) if (cacheID.HasValue) { msgOut.AddBinary(MessageOutFieldID.CacheItemID, cacheID.Value.ToByteArray()); } msgOut.Send(WaveServerComponent.CacheAgent, CacheAgentMessageID.CacheHashCheck); break; } case CacheAgentMessageID.SendWABCacheCIID: { BinaryField bin = (BinaryField)data[MessageOutFieldID.CacheItemID]; if (bin.Data != null) { CacheItemID temp = new CacheItemID(bin.Data); if (!cacheID.HasValue || !cacheID.Value.Equals(temp)) { cacheID = temp; goto case CacheAgentMessageID.ClearCache; } } break; } case CacheAgentMessageID.ClearCache: { Server.Clear(); break; } } } } }
public void OpenMediaStream(string contentID, byte[] streamSessionID = null) { WaveMessage msg = new WaveMessage(); msg.AddBinary(MessageOutFieldID.ContentReferenceID, StringHelper.GetBytes(contentID)); if (streamSessionID != null) { msg.AddBinary(MediaReferenceFieldID.StreamSessionID, streamSessionID); } msg.Send(WaveServerComponent.MediaAgent, MediaAgentMessageID.OpenStream); }
private void SendForm(FormAction trigger, ActionSet actionSet, Node sourceNode, BlockBase sourceBlock, long sourceViewID, bool expectResponse = false) { if (sourceNode != null) { WaveMessage msg = new WaveMessage(); Core.Navigation.Requests.Add(msg, sourceViewID, trigger.Transition, trigger.IsPopUp); if (Core.CSLVersion == WaveCSLVersion.Version5) { msg.AddInt16(NaviAgentFieldID.ActionTypeID, (short)trigger.ActionType); msg.AddBoolean(NaviAgentFieldID.FormRequiresNoWait, trigger.WaitForNode); } else { msg.AddByte(NaviAgentFieldID.ActionRef, (byte)trigger.FormID); } FieldList payload = FieldList.CreateField(NaviAgentFieldID.ActionPayload); payload.AddString(NaviAgentFieldID.FormRequestURL, trigger.FormURL); sourceNode.AttachFormData((short)trigger.FormID, payload); msg.AddFieldList(payload); Core.System.Location.AddLocationData(msg); if (sourceNode.CacheID != null) { msg.AddBinary(MessageOutFieldID.CacheItemID, sourceNode.CacheID.Value.ToByteArray()); } else { msg.AddString(MessageOutFieldID.ItemURI, sourceNode.URI); } if (Core.CSLVersion != WaveCSLVersion.Version5) { msg.AddInt32(NaviAgentFieldID.ActionSetID, actionSet.DefinitionID); } msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.Action); if (expectResponse) { Core.UI.SignalViewNavigationStart(sourceViewID); } } }
private void GoToNodeByID(CacheItemID?id, string nodeURI, NodeTransition transition, bool isPopup, long targetViewID) { // check if node is in the cache object data = null; if (id.HasValue) { data = Core.Cache.Server[id.Value]; } if (data == null) { // request node from server if (!String.IsNullOrEmpty(nodeURI)) { WaveMessage msg = new WaveMessage(); Core.Navigation.Requests.Add(msg, targetViewID, transition, isPopup); msg.AddString(MessageOutFieldID.ItemURI, nodeURI); Core.System.Location.AddLocationData(msg); msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.RequestNodeOnCacheError); Core.UI.SignalViewNavigationStart(targetViewID); } } else { // load node from cache UnpackCachedNode((FieldList)data, transition, isPopup, targetViewID); // inform server if (id.HasValue || !String.IsNullOrEmpty(nodeURI)) { WaveMessage msg = new WaveMessage(); if (id.HasValue) { msg.AddBinary(MessageOutFieldID.CacheItemID, id.Value.ToByteArray()); } else { msg.AddString(MessageOutFieldID.ItemURI, nodeURI); } msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.SubscribeToNodeWithoutRequest); } } }
private void SendFrameAcknowledgement(byte[] ciid, byte[] cRefID, short frameNumber) { WaveMessage msg = new WaveMessage(); if (ciid != null) { msg.AddBinary(MessageOutFieldID.CacheItemID, ciid); } else { msg.AddBinary(MessageOutFieldID.ContentReferenceID, cRefID); } msg.AddInt16(MediaReferenceFieldID.FrameNumber, frameNumber); msg.Send(WaveServerComponent.MediaAgent, MediaAgentMessageID.FrameAcknowledgement); }
public void GoToNodeByURI(string nodeURI, NodeTransition transition, bool isPopup, long sourceViewID, bool refresh = false) { // check if node is in the cache object data = Core.Cache.Server[nodeURI]; if ((data == null) || refresh) { // not in cache, ask server Core.Network.EnsureConnection(); WaveMessage msg = new WaveMessage(); Core.Navigation.Requests.Add(msg, sourceViewID, transition, isPopup); if (refresh) { msg.AddBoolean(MessageOutFieldID.RefreshingNode, true); } msg.AddString(MessageOutFieldID.ItemURI, nodeURI); Core.System.Location.AddLocationData(msg); msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.RequestNode); Core.UI.SignalViewNavigationStart(sourceViewID); } else { if (data is FieldList) { // inform server WaveMessage msg = new WaveMessage(); msg.AddString(MessageOutFieldID.ItemURI, nodeURI); msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.SubscribeToNodeWithoutRequest); // unpack UnpackCachedNode((FieldList)data, transition, isPopup, sourceViewID); } else { DebugHelper.Out("Unexpected data type: {0}", data.GetType().FullName); } } }
private void GoToApplication(string applicationHome, string applicationHomeNode, NodeTransition transition, bool isPopup, long sourceViewID) { //TODO: check in cache first, before trying to send a message WaveMessage msg = new WaveMessage(); Core.Navigation.Requests.Add(msg, sourceViewID, transition, isPopup); msg.AddString(NaviAgentFieldID.ApplicationURN, applicationHome); if (applicationHomeNode != null) { msg.AddString(MessageOutFieldID.ItemURI, applicationHomeNode); } Core.System.Location.AddLocationData(msg); msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.GotoAnotherApplicationNode); Core.UI.SignalViewNavigationStart(sourceViewID); }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is UserManagerMessageID) { if (data != null) { switch ((UserManagerMessageID)msgID) { case UserManagerMessageID.Challenge: { bool createAccount = false; // check if there is login already (otherwise set defaults) if (!Core.Application.HasLogin) { createAccount = true; Core.Application.UpdateCredentials(GenerateNewUsername(), StringHelper.GetBytes(DefaultPassword)); } // get CSL version WaveCSLVersion serverCSL = (WaveCSLVersion)(data[UserManagerFieldID.CSLVersion].AsShort() ?? (short)WaveCSLVersion.Unknown); switch (serverCSL) { case WaveCSLVersion.Version5: case WaveCSLVersion.Version4: Core.CSLVersion = serverCSL; break; default: Core.CSLVersion = WaveCSLVersion.Version3; break; } // get maximum protocol version WaveProtocolVersion serverProto = (WaveProtocolVersion)(data[UserManagerFieldID.MaxWeMessageVersion].AsByte() ?? (byte)WaveProtocolVersion.Unknown); switch (serverProto) { case WaveProtocolVersion.Version4: Core.ProtocolVersion = WaveProtocolVersion.Version4; break; default: Core.ProtocolVersion = WaveProtocolVersion.Version3; break; } // get challenge BinaryField challenge = (BinaryField)data[UserManagerFieldID.Challenge]; // assemble login message WaveMessage msgOut = new WaveMessage(); msgOut.AddInt16(UserManagerFieldID.CSLVersion, (short)Core.CSLVersion); msgOut.AddBoolean(UserManagerFieldID.EncryptSession, Core.UseEncryption); msgOut.AddInt16(UserManagerFieldID.PriorityMask, NetworkAgent.PrioritiesActiveMask); msgOut.AddBinary(UserManagerFieldID.UserCredentials, ProcessChallenge(challenge.Data, Core.Application, createAccount)); msgOut.AddBoolean(UserManagerFieldID.CreateAccount, createAccount); // cache hash byte[] cacheHash = Core.Cache.CacheHash; msgOut.AddBinary(CacheAgentFieldID.CacheHashCompressed, (cacheHash.Length > 0) ? CompressionHelper.GZipBuffer(cacheHash) : cacheHash); // cache ID (if any) if (Core.Cache.CacheID.HasValue) { msgOut.AddBinary(MessageOutFieldID.CacheItemID, Core.Cache.CacheID.Value.ToByteArray()); } // compiling device settings FieldList deviceSettingsList = FieldList.CreateField(UserManagerFieldID.DeviceSettings); deviceSettingsList.AddString(UserManagerFieldID.DeviceBuildID, Core.BuildID); deviceSettingsList.AddBoolean(NaviAgentFieldID.DeviceSupportsTouch, true); deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceScreenResolutionWidth, 480); deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceScreenResolutionHeight, 800); DeviceGroup[] devs = Core.System.SupportedDeviceGroups; foreach (DeviceGroup dev in devs) { deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceProfileGroup, (short)dev); } deviceSettingsList.AddString(UserManagerFieldID.LanguageID, CultureInfo.CurrentCulture.Name); deviceSettingsList.AddString(UserManagerFieldID.Timezone, Core.Settings.TimeZone); deviceSettingsList.AddBoolean(UserManagerFieldID.AlphaSupport, true); deviceSettingsList.AddBoolean(UserManagerFieldID.CompressionSupport, true); msgOut.AddFieldList(deviceSettingsList); // compiling application request list FieldList appRequestList = FieldList.CreateField(UserManagerFieldID.ApplicationRequest); appRequestList.AddString(NaviAgentFieldID.ApplicationURN, Core.Application.URI); appRequestList.AddInt16(NaviAgentFieldID.ApplicationRequestAction, (short)AppRequestAction.GetAppEntryPage); msgOut.AddFieldList(appRequestList); msgOut.Send(WaveServerComponent.UserManager, UserManagerMessageID.Login); Core.UI.SignalViewNavigationStart(Core.UI.RootViewID); break; } case UserManagerMessageID.EncryptionKeys: { // setting encryption (if allowed by build configuration) if (Core.UseEncryption && (sessionHandshakeFish != null)) { BinaryField sessionKeyField = (BinaryField)data[UserManagerFieldID.SessionKey]; byte[] sessionKey = (byte[])sessionKeyField.Data; sessionHandshakeFish.Decrypt(sessionKey, sessionKey.Length); BinaryField globalServerKeyField = (BinaryField)data[UserManagerFieldID.GlobalServerKey]; byte[] globalServerKey = (byte[])globalServerKeyField.Data; sessionHandshakeFish.Decrypt(globalServerKey, globalServerKey.Length); Core.NotifyEncryptionKeysChanged(this, sessionKey, globalServerKey); } else { Core.NotifyEncryptionKeysChanged(this, null, null); } // setting login data StringField userName = (StringField)data[UserManagerFieldID.CreatedAccountUserName]; if (userName != null) { BinaryField userPass = (BinaryField)data[UserManagerFieldID.CreatedAccountPasswordHash]; if ((userPass != null) && (sessionHandshakeFish != null)) { byte[] passBuffer = (byte[])userPass.Data.Clone(); sessionHandshakeFish.Decrypt(passBuffer, passBuffer.Length); Core.Application.UpdateCredentials(userName.Data, passBuffer); // no longer needed sessionHandshakeFish = null; } } break; } case UserManagerMessageID.LoginResponse: { if (!authenticated) { Int16Field loginStatus = (Int16Field)data[UserManagerFieldID.LoginStatus]; switch ((UserLoginStatus)loginStatus.Data) { case UserLoginStatus.Success: { // signal authentication success Core.NotifyAuthentication(this, data[UserManagerFieldID.SessionInfo].AsByteArray()); // preparing login data message FieldList appContext = (FieldList)data[UserManagerFieldID.ApplicationContext]; if (appContext != null) { int appID = appContext[MessageOutFieldID.ApplicationID].AsInteger() ?? 0; string unqualifiedAppURI = appContext[UserManagerFieldID.ApplicationUnqualifiedURI].AsText(); string fullyQualifiedAppURI = appContext[UserManagerFieldID.ApplicationFullyQualifiedURI].AsText(); Core.NotifySuccessfulLogin(this, appID, unqualifiedAppURI, fullyQualifiedAppURI); } authenticated = true; authenticatedEver = true; break; } case UserLoginStatus.FailedInvalidCredentials: Core.NotifyTerminateSession(this, SessionTerminationReasonCode.InvalidCredentials); break; case UserLoginStatus.FailedNoUser: Core.NotifyTerminateSession(this, SessionTerminationReasonCode.NoSuchUser); break; } } break; } } } } }